mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
24
_examples/response-writer/write-gzip/main.go
Normal file
24
_examples/response-writer/write-gzip/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris/v12"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// app.Use(iris.Gzip)
|
||||
// func(ctx iris.Context) { ctx.Gzip(true/false)}
|
||||
// OR:
|
||||
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.Listen(":8080")
|
||||
}
|
||||
Reference in New Issue
Block a user