mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 21:15:56 +00:00
minor
Change the new ctx.Compres to ctx.CompressWriter and iris.Compress and iris.CompressReader as one iris.Compression Update the README example (master development branch) Former-commit-id: fb67858fe5be5662b5816df41020c28ff9a8c6f6
This commit is contained in:
@@ -11,7 +11,7 @@ func main() {
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
// HERE and you are ready to GO:
|
||||
app.Use(iris.Compress, iris.CompressReader)
|
||||
app.Use(iris.Compression)
|
||||
|
||||
app.Get("/", send)
|
||||
app.Post("/", receive)
|
||||
@@ -41,7 +41,7 @@ func receive(ctx iris.Context) {
|
||||
/* Manually:
|
||||
func enableCompression(ctx iris.Context) {
|
||||
// Enable writing using compression (deflate, gzip, brotli, snappy, s2):
|
||||
err := ctx.Compress(true)
|
||||
err := ctx.CompressWriter(true)
|
||||
if err != nil {
|
||||
ctx.Application().Logger().Debugf("writer: %v", err)
|
||||
// if you REQUIRE server to SEND compressed data then `return` here.
|
||||
|
||||
@@ -35,8 +35,10 @@ func TestHandlerUsingNetHTTP(t *testing.T) {
|
||||
ctx.WriteString("Hello, World!")
|
||||
}
|
||||
|
||||
// A shortcut for net/http/httptest.NewRecorder/NewRequest.
|
||||
w := httptest.NewRecorder()
|
||||
r := httptest.NewRequest("GET", "/", nil)
|
||||
|
||||
httptest.Do(w, r, handler)
|
||||
if expected, got := "Hello, World!", w.Body.String(); expected != got {
|
||||
t.Fatalf("expected body: %s but got: %s", expected, got)
|
||||
|
||||
@@ -17,7 +17,7 @@ func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/users", func(ctx iris.Context) {
|
||||
ctx.Compress(true)
|
||||
ctx.CompressWriter(true)
|
||||
ctx.ContentType("text/html")
|
||||
|
||||
userList := []string{
|
||||
|
||||
@@ -14,7 +14,7 @@ func main() {
|
||||
// - {{ current }}
|
||||
app.RegisterView(iris.HTML("./templates", ".html"))
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.Compress(true) // enable compression based on Accept-Encoding (e.g. "gzip").
|
||||
ctx.CompressWriter(true) // enable compression based on Accept-Encoding (e.g. "gzip").
|
||||
ctx.ViewData("Name", "iris") // the .Name inside the ./templates/hi.html.
|
||||
ctx.View("hi.html") // render the template with the file name relative to the './templates'.
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// ExecuteTemplate renders a "tmpl" partial template to the `Context.ResponseWriter`.
|
||||
func ExecuteTemplate(ctx iris.Context, tmpl templates.Partial) {
|
||||
ctx.Compress(true)
|
||||
ctx.CompressWriter(true)
|
||||
ctx.ContentType("text/html")
|
||||
templates.WriteTemplate(ctx, tmpl)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func main() {
|
||||
// TIP: append .Reload(true) to reload the templates on each request.
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.Compress(true)
|
||||
ctx.CompressWriter(true)
|
||||
ctx.ViewData("", mypage{"My Page title", "Hello world!"})
|
||||
ctx.View("mypage.html")
|
||||
// Note that: you can pass "layout" : "otherLayout.html" to bypass the config's Layout property
|
||||
|
||||
@@ -17,7 +17,7 @@ func main() {
|
||||
app.HandleDir("/", "./client")
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
// ctx.Compress(true)
|
||||
// ctx.CompressWriter(true)
|
||||
ctx.ServeFile("./client/hello.html")
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user