-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (59 loc) · 1.55 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
package main
import (
"fmt"
"franmework/controller"
"franmework/dao/mysql"
"franmework/dao/redis"
"franmework/logger"
"franmework/pkg/snowflake"
"franmework/router"
"franmework/setting"
"os"
)
// @title franmework项目接口文档
// @version 1.0
// @description Go web开发
// @contact.name pang
// @host 127.0.0.1:8084
// @BasePath /api/v1
func main() {
if len(os.Args) < 2 {
fmt.Println("need config file.eg: franmework config.yaml")
return
}
// 加载配置
if err := setting.Init(os.Args[1]); err != nil {
fmt.Printf("load config failed, err:%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
}
// 注册路由
r := router.SetupRouter(setting.Conf.Mode)
err := r.Run(fmt.Sprintf(":%d", setting.Conf.Port))
if err != nil {
fmt.Printf("run server failed, err:%v\n", err)
return
}
}