mirror of
https://github.com/kataras/iris.git
synced 2025-12-24 05:17:03 +00:00
create a new package, name it as hero, I was thinking super or superb but hero is better name for what it does - the goal is to split the new 'mvc handlers' from the mvc system because they are not the same, users should know that they can use these type of rich binded handlers without controllers as well, like a normal handler and that I implemented here, the old files exist on the mvc package but will be removed at the next commit, I have to decide if we want type aliases for Result or no
Former-commit-id: cb775edc72bedc88aeab4c5a6de6bfc6bd56fae2
This commit is contained in:
55
_examples/http_responsewriter/herotemplate/app.go
Normal file
55
_examples/http_responsewriter/herotemplate/app.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
|
||||
"github.com/kataras/iris/_examples/http_responsewriter/herotemplate/template"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
// $ go get -u github.com/shiyanhui/hero/hero
|
||||
// $ go run app.go
|
||||
//
|
||||
// Read more at https://github.com/shiyanhui/hero/hero
|
||||
func main() {
|
||||
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/users", func(ctx iris.Context) {
|
||||
var userList = []string{
|
||||
"Alice",
|
||||
"Bob",
|
||||
"Tom",
|
||||
}
|
||||
|
||||
// Had better use buffer sync.Pool.
|
||||
// Hero exports GetBuffer and PutBuffer for this.
|
||||
//
|
||||
// buffer := hero.GetBuffer()
|
||||
// defer hero.PutBuffer(buffer)
|
||||
buffer := new(bytes.Buffer)
|
||||
template.UserList(userList, buffer)
|
||||
|
||||
if _, err := ctx.Write(buffer.Bytes()); err != nil {
|
||||
log.Printf("ERR: %s\n", err)
|
||||
}
|
||||
})
|
||||
|
||||
app.Get("/users2", func(ctx iris.Context) {
|
||||
var userList = []string{
|
||||
"Alice",
|
||||
"Bob",
|
||||
"Tom",
|
||||
}
|
||||
|
||||
// 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.
|
||||
template.UserListToWriter(userList, ctx)
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
Reference in New Issue
Block a user