-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathmain.go
More file actions
94 lines (76 loc) · 1.96 KB
/
main.go
File metadata and controls
94 lines (76 loc) · 1.96 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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())
//这里仅为示例,默认情况下,开启的模式就是development模式
app.SetDevelopmentMode()
//使用json标签
app.HttpServer.SetEnabledBindUseJsonTag(true)
//设置gzip开关
//app.HttpServer.SetEnabledGzip(true)
//设置路由
InitRoute(app.HttpServer)
//启动 监控服务
//app.SetPProfConfig(true, 8081)
// 开始服务
port := 8080
fmt.Println("dotweb.StartServer => " + strconv.Itoa(port))
err := app.StartServer(port)
fmt.Println("dotweb.StartServer error => ", err)
}
func TestBind(ctx dotweb.Context) error {
type UserInfo struct {
UserName string
Sex int
}
user := new(UserInfo)
errstr := "no error"
if err := ctx.Bind(user); err != nil {
errstr = err.Error()
} else {
}
return ctx.WriteString("TestBind [" + errstr + "] " + fmt.Sprint(user))
}
func GetBind(ctx dotweb.Context) error {
//type UserInfo struct {
// UserName string `form:"user"`
// Sex int `form:"sex"`
//}
type UserInfo struct {
UserName string `json:"user"`
Sex int `json:"sex"`
}
user := new(UserInfo)
errstr := "no error"
if err := ctx.Bind(user); err != nil {
errstr = err.Error()
} else {
}
return ctx.WriteString("GetBind [" + errstr + "] " + fmt.Sprint(user))
}
func PostJsonBind(ctx dotweb.Context) error{
type UserInfo struct {
UserName string `json:"user"`
Sex int `json:"sex"`
}
user := new(UserInfo)
errstr := "no error"
if err := ctx.BindJsonBody(user); err != nil {
errstr = err.Error()
} else {
}
return ctx.WriteString("PostBind [" + errstr + "] " + fmt.Sprint(user))
}
func InitRoute(server *dotweb.HttpServer) {
server.Router().POST("/", TestBind)
server.Router().GET("/getbind", GetBind)
server.Router().POST("/jsonbind", PostJsonBind)
}