-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
47 lines (41 loc) · 1.05 KB
/
server.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
package main
import (
"github.com/gin-gonic/gin"
"github.com/tsingsun/woocoo/contrib/opentelemetry/otelweb"
"github.com/tsingsun/woocoo/pkg/conf"
"github.com/tsingsun/woocoo/pkg/log"
"github.com/tsingsun/woocoo/web"
"github.com/tsingsun/woocoo/web/handler/gql"
)
type login struct {
Username string `form:"username" json:"username" binding:"required"`
Password string `form:"password" json:"password" binding:"required"`
}
// User demo
type User struct {
UserName string
FirstName string
LastName string
}
func main() {
cfg := conf.New().Load()
log.NewBuiltIn()
httpSvr := web.New(web.Configuration(cfg.Sub("web")),
web.RegisterMiddleware(otelweb.New()),
web.RegisterMiddleware(gql.New()),
web.GracefulStop(),
)
r := httpSvr.Router().Engine
r.GET("/", func(c *gin.Context) {
c.String(200, "hello world")
})
r.GET("/abort", func(c *gin.Context) {
c.Abort()
})
r.NoRoute(func(c *gin.Context) {
c.JSON(404, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"})
})
if err := httpSvr.Run(); err != nil {
log.Error(err)
}
}