-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.go
52 lines (39 loc) · 1023 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
51
52
package main
import (
"fmt"
"gin_bbs/app/cron"
"net/http"
"github.com/lexkong/log"
"github.com/gin-gonic/gin"
"gin_bbs/config"
"gin_bbs/bootstrap"
"github.com/spf13/pflag"
)
var (
// 需要 mock data,注意该操作会覆盖数据库;只在非 release 时生效
needMock = pflag.BoolP("mock", "m", false, "need mock data")
)
func main() {
// 解析命令行参数
pflag.Parse()
// 初始化配置
config.InitConfig("", true)
// gin setup
g := gin.New()
bootstrap.SetupGin(g)
// db setup
db, err := bootstrap.SetupDB(*needMock)
if err != nil {
return
}
defer db.Close()
// router setup
bootstrap.SetupRouter(g)
// cron
cron.New().Start()
// 启动
fmt.Printf("\n\n-------------------------------------------------- Start to listening the incoming requests on http address: %s --------------------------------------------------\n\n", config.AppConfig.Addr)
if err := http.ListenAndServe(config.AppConfig.Addr, g); err != nil {
log.Fatal("http server 启动失败", err)
}
}