forked from devfeel/dotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (56 loc) · 1.48 KB
/
main.go
File metadata and controls
71 lines (56 loc) · 1.48 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"github.com/devfeel/dotweb"
"github.com/devfeel/dotweb/framework/file"
"strconv"
)
func main() {
//初始化DotServer
app := dotweb.New()
//设置dotserver日志目录
app.SetLogPath(file.GetCurrentDirectory())
//app.SetDevelopmentMode()
//设置gzip开关
//app.HttpServer.SetEnabledGzip(true)
//设置路由
InitRoute(app.HttpServer)
//set default template path
app.HttpServer.Renderer().SetTemplatePath("d:/gotmp/")
//启动 监控服务
//app.SetPProfConfig(true, 8081)
// 开始服务
port := 8080
fmt.Println("dotweb.StartServer => " + strconv.Itoa(port))
err := app.StartServer(port)
fmt.Println("dotweb.StartServer error => ", err)
}
type UserInfo struct {
UserName string
Sex bool
}
type BookInfo struct {
Name string
Size int64
}
func NotExistView(ctx dotweb.Context) error {
err := ctx.View("1.html")
return err
}
func TestView(ctx dotweb.Context) error {
ctx.ViewData().Set("data", "图书信息")
ctx.ViewData().Set("user", &UserInfo{UserName: "user1", Sex: true})
m := make([]*BookInfo, 5)
m[0] = &BookInfo{Name: "book0", Size: 1}
m[1] = &BookInfo{Name: "book1", Size: 10}
m[2] = &BookInfo{Name: "book2", Size: 100}
m[3] = &BookInfo{Name: "book3", Size: 1000}
m[4] = &BookInfo{Name: "book4", Size: 10000}
ctx.ViewData().Set("Books", m)
err := ctx.View("testview.html")
return err
}
func InitRoute(server *dotweb.HttpServer) {
server.Router().GET("/", TestView)
server.Router().GET("/noview", NotExistView)
}