mirror of
https://github.com/kataras/iris.git
synced 2025-12-27 23:07:03 +00:00
(#1554) Add support for all common compressions (write and read)
- Remove the context.Context interface and export the *context, the iris.Context now points to the pointer\nSupport compression and rate limiting in the FileServer\nBit of code organisation Former-commit-id: ad1c61bf968059510c6be9e7f2cceec7da70ba17
This commit is contained in:
@@ -17,7 +17,7 @@ func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/users", func(ctx iris.Context) {
|
||||
ctx.Gzip(true)
|
||||
ctx.Compress(true)
|
||||
ctx.ContentType("text/html")
|
||||
|
||||
userList := []string{
|
||||
@@ -35,11 +35,9 @@ func main() {
|
||||
// template.UserList(userList, buffer)
|
||||
// ctx.Write(buffer.Bytes())
|
||||
|
||||
// using an io.Writer for automatic buffer management (i.e. hero built-in buffer pool),
|
||||
// iris context implements the io.Writer by its ResponseWriter
|
||||
// which is an enhanced version of the standard http.ResponseWriter
|
||||
// but still 100% compatible, GzipResponseWriter too:
|
||||
// _, err := template.UserListToWriter(userList, ctx.GzipResponseWriter())
|
||||
// iris context implements the io.Writer:
|
||||
// _, err := template.UserListToWriter(userList, ctx)
|
||||
// OR:
|
||||
buffer := new(bytes.Buffer)
|
||||
template.UserList(userList, buffer)
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ func main() {
|
||||
// - {{ current }}
|
||||
app.RegisterView(iris.HTML("./templates", ".html"))
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.ViewData("Name", "iris") // the .Name inside the ./templates/hi.html
|
||||
ctx.Gzip(true) // enable gzip for big files
|
||||
ctx.View("hi.html") // render the template with the file name relative to the './templates'
|
||||
ctx.Compress(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'.
|
||||
})
|
||||
|
||||
// http://localhost:8080/
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
// ExecuteTemplate renders a "tmpl" partial template to the `context#ResponseWriter`.
|
||||
// ExecuteTemplate renders a "tmpl" partial template to the `Context.ResponseWriter`.
|
||||
func ExecuteTemplate(ctx iris.Context, tmpl templates.Partial) {
|
||||
ctx.Gzip(true)
|
||||
ctx.Compress(true)
|
||||
ctx.ContentType("text/html")
|
||||
templates.WriteTemplate(ctx.ResponseWriter(), tmpl)
|
||||
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.Gzip(true)
|
||||
ctx.Compress(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
|
||||
|
||||
@@ -201,9 +201,9 @@ func AssetNames() []string {
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"views/includes/_partial.jet": viewsIncludes_partialJet,
|
||||
"views/includes/blocks.jet": viewsIncludesBlocksJet,
|
||||
"views/index.jet": viewsIndexJet,
|
||||
"views/includes/_partial.jet": viewsIncludes_partialJet,
|
||||
"views/includes/blocks.jet": viewsIncludesBlocksJet,
|
||||
"views/index.jet": viewsIndexJet,
|
||||
"views/layouts/application.jet": viewsLayoutsApplicationJet,
|
||||
}
|
||||
|
||||
@@ -246,15 +246,16 @@ type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"views": &bintree{nil, map[string]*bintree{
|
||||
"includes": &bintree{nil, map[string]*bintree{
|
||||
"_partial.jet": &bintree{viewsIncludes_partialJet, map[string]*bintree{}},
|
||||
"blocks.jet": &bintree{viewsIncludesBlocksJet, map[string]*bintree{}},
|
||||
"views": {nil, map[string]*bintree{
|
||||
"includes": {nil, map[string]*bintree{
|
||||
"_partial.jet": {viewsIncludes_partialJet, map[string]*bintree{}},
|
||||
"blocks.jet": {viewsIncludesBlocksJet, map[string]*bintree{}},
|
||||
}},
|
||||
"index.jet": &bintree{viewsIndexJet, map[string]*bintree{}},
|
||||
"layouts": &bintree{nil, map[string]*bintree{
|
||||
"application.jet": &bintree{viewsLayoutsApplicationJet, map[string]*bintree{}},
|
||||
"index.jet": {viewsIndexJet, map[string]*bintree{}},
|
||||
"layouts": {nil, map[string]*bintree{
|
||||
"application.jet": {viewsLayoutsApplicationJet, map[string]*bintree{}},
|
||||
}},
|
||||
}},
|
||||
}}
|
||||
@@ -305,4 +306,3 @@ func _filePath(dir, name string) string {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user