-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (38 loc) · 810 Bytes
/
main.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
package main
import (
"flag"
"net/http"
"gogo/ctx"
_ "gogo/db"
"gogo/log"
"gogo/router"
"github.com/gin-gonic/gin"
)
func main() {
// parse command line args
port := flag.String("port", "8080", "server start port")
flag.Parse()
log.Info("port: ", *port)
r := gin.New()
// use middleware
r.Use(gin.Logger(), gin.Recovery())
// handle no route request
r.NoRoute(ctx.Handler(func(c *ctx.Ctx) {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
"code": "999999",
})
}))
// handle no method request
r.NoMethod(ctx.Handler(func(c *ctx.Ctx) {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
"code": "999999",
})
}))
// register router
router.Router(r)
if err := r.Run(":" + *port); err != nil {
log.Fatal(err)
} else {
log.Info("start server success")
}
}