-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
app.go
52 lines (41 loc) · 1.07 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bytes"
"github.com/kataras/iris/v12/_examples/view/herotemplate/template"
"github.com/kataras/iris/v12"
)
// $ 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) {
ctx.CompressWriter(true)
ctx.ContentType("text/html")
userList := []string{
"Alice",
"Bob",
"Tom",
}
// Had better use buffer sync.Pool.
// Hero(github.com/shiyanhui/hero/hero) exports GetBuffer and PutBuffer for this.
//
// buffer := hero.GetBuffer()
// defer hero.PutBuffer(buffer)
// buffer := new(bytes.Buffer)
// template.UserList(userList, buffer)
// ctx.Write(buffer.Bytes())
// iris context implements the io.Writer:
// _, err := template.UserListToWriter(userList, ctx)
// OR:
buffer := new(bytes.Buffer)
template.UserList(userList, buffer)
_, err := ctx.Write(buffer.Bytes())
if err != nil {
ctx.StopWithError(iris.StatusInternalServerError, err)
return
}
})
app.Listen(":8080")
}