mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 20:07:04 +00:00
add example for the simple context#WriteGzip
Former-commit-id: 3b4e0834370ebde5e4796b3d75cdbd5c2c25093f
This commit is contained in:
21
_examples/http_responsewriter/write-gzip/main.go
Normal file
21
_examples/http_responsewriter/write-gzip/main.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.WriteGzip([]byte("Hello World!"))
|
||||
ctx.Header("X-Custom",
|
||||
"Headers can be set here after WriteGzip as well, because the data are kept before sent to the client when using the context's GzipResponseWriter and ResponseRecorder.")
|
||||
})
|
||||
|
||||
app.Get("/2", func(ctx iris.Context) {
|
||||
// same as the `WriteGzip`.
|
||||
// However GzipResponseWriter gives you more options, like
|
||||
// reset data, disable and more, look its methods.
|
||||
ctx.GzipResponseWriter().WriteString("Hello World!")
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
Reference in New Issue
Block a user