-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
39 lines (32 loc) · 818 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
package main
import (
"flag"
"fmt"
"gin-skeleton/config"
"gin-skeleton/handler"
"gin-skeleton/middleware"
"gin-skeleton/svc"
"gin-skeleton/svc/logx"
"github.com/gin-gonic/gin"
)
var configFile = flag.String("f", "./.env.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
svc.MustLoad(*configFile, &c)
if c.Debug {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
server := gin.New()
server.HandleMethodNotAllowed = true
svcCtx := svc.NewServiceContext(c)
middleware.RegisterGlobalMiddlewares(server)
handler.RegisterHandlers(server, svcCtx)
fmt.Printf("Starting server at localhost%s...\n", c.App.Port)
if err := server.Run(c.App.Port); err != nil {
fmt.Printf("Start server error,err=%v", err)
logx.Errorf("Start server error:%v", err)
}
}