-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (40 loc) · 1.16 KB
/
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
51
package main
import (
"flag"
"fmt"
"runtime"
"katana-demo/common"
"katana-demo/controller"
"github.com/22km/katana"
"github.com/22km/katana/log"
)
func main() {
configPath := flag.String("config", "app.dev.yaml", "config file's path")
flag.Parse()
// 初始化启动配置
if err := common.LoadAppConf(*configPath); err != nil {
panic("init config failed! err:" + err.Error())
}
// 设置 proc
if common.AppConf().Base.GoMaxProcs > 1 {
runtime.GOMAXPROCS(common.AppConf().Base.GoMaxProcs)
} else {
runtime.GOMAXPROCS(runtime.NumCPU())
}
// 初始化日志
if err := log.Init(common.AppConf().Log); err != nil {
panic("init log failed! err:" + err.Error())
}
defer log.Close()
// web server 路由 & 启动
engine := katana.New(common.AppConf().Base.Mode)
engine.Use(katana.GinRecovery(), katana.Recorder())
say := engine.Group("/say")
say.ANY("/hello", controller.SayHello)
say.GET("/hi", controller.SayHi)
fmt.Println("try http://127.0.0.1:8088/say/hello")
fmt.Println("or http://127.0.0.1:8088/say/hi?who=outside")
if err := engine.Run(common.AppConf().Base.Port); err != nil {
panic("boot server failed! err:" + err.Error())
}
}