-
Notifications
You must be signed in to change notification settings - Fork 13
/
example.go
30 lines (24 loc) · 750 Bytes
/
example.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
package main
import (
"fmt"
"github.com/flysnow-org/soha"
"html/template"
"net/http"
)
type h map[string]interface{}
func main() {
tmpl,err:=template.New("index.html").Funcs(soha.CreateFuncMap()).ParseFiles("example/index.html")
tmpl = template.Must(tmpl, err)
sliceData:=[]string{"a","b","c","d","e","f","g"}
sliceData1:=[]string{"d","e","f","g","h","i","j","k"}
sliceData2:=[]user{{Name:"张三",Age:12},{Name:"李四",Age:18},{Name:"王武",Age:20}}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w,h{"sliceData":sliceData,"sliceData1":sliceData1,"sliceData2":sliceData2})
})
fmt.Println("Please visit 127.0.0.1 ")
http.ListenAndServe(":80", nil)
}
type user struct {
Name string
Age int
}