-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (60 loc) · 1.71 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"bluebell/controller"
"bluebell/dao/mysql"
"bluebell/dao/redis"
"bluebell/logger"
snowflake "bluebell/pkg/snowflake"
"bluebell/router"
"bluebell/setting"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
//if len(os.Args) < 2 {
// fmt.Println("need config file.eg: bluebell config.yaml")
// return
//}
// 加载配置
// linux: /mnt/d/go_project/bluebell/conf/config.yaml
// windows: D:/go_project/bluebell/conf/config.yaml
if err := setting.Init("./conf/config.yaml"); err != nil {
fmt.Printf("load config failed, err1:%v\n", err)
return
}
if err := logger.Init(setting.Conf.LogConfig, setting.Conf.Mode); err != nil {
fmt.Printf("init logger failed, err:%v\n", err)
return
}
if err := mysql.Init(setting.Conf.MySQLConfig); err != nil {
fmt.Printf("init mysql failed, err:%v\n", err)
return
}
defer mysql.Close() // 程序退出关闭数据库连接
if err := redis.Init(setting.Conf.RedisConfig); err != nil {
fmt.Printf("init redis failed, err:%v\n", err)
return
}
defer redis.Close()
if err := snowflake.Init(setting.Conf.StartTime, setting.Conf.MachineID); err != nil {
fmt.Printf("init snowflake failed, err:%v\n", err)
return
}
//// 初始化gin框架内置的校验器使用的翻译器
//if err := controller.InitTrans("zh"); err != nil {
// fmt.Printf("init validator trans failed, err:%v\n", err)
// return
//}
//初始化gin框架内置的校验器使用的翻译器
if err := controller.InitTrans("zh"); err != nil {
fmt.Printf("init trans faild, err:%v", err)
return
}
// 注册路由
r := router.SetupRouter()
err := r.Run(fmt.Sprintf(":%d", setting.Conf.Port))
if err != nil {
fmt.Printf("run server failed, err:%v\n", err)
return
}
}