forked from Hua-ymsk/TikTok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (45 loc) · 955 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
package main
import (
"errors"
"fmt"
"tiktok/common/snowflake"
"tiktok/dao"
"tiktok/dao/mysql"
"tiktok/middleware"
"tiktok/router"
"tiktok/setting"
)
func main() {
// 加载config
if err := setting.Init(); err != nil {
fmt.Println("load config err:", err)
return
}
// 雪花算法初始化
if err := snowflake.Init(); err != nil {
fmt.Println("init snowflake err: ", err)
return
}
// logger初始化
if err := middleware.InitLogger(true); err != nil {
fmt.Println("init logger err:", err)
return
}
// 原生sql
if err := dao.Connect(); err != nil {
fmt.Println(errors.New("connect error"))
return
}
defer dao.Close()
// gorm初始化
if err := mysql.Init(setting.Conf.MysqlConfig); err != nil {
fmt.Println("init mysql err:", err)
return
}
// router初始化
r := router.InitRouter()
if err := r.Run(fmt.Sprintf(":%d", setting.Conf.Port)); err != nil {
fmt.Println("init router err:", err)
return
}
}