forked from Q1mi/bubble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (36 loc) · 831 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
package main
import (
"bubble/dao"
"bubble/models"
"bubble/routers"
"bubble/setting"
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage:./bubble conf/config.ini")
return
}
// 加载配置文件
if err := setting.Init(os.Args[1]); err != nil {
fmt.Printf("load config from file failed, err:%v\n", err)
return
}
// 创建数据库
// sql: CREATE DATABASE bubble;
// 连接数据库
err := dao.InitMySQL(setting.Conf.MySQLConfig)
if err != nil {
fmt.Printf("init mysql failed, err:%v\n", err)
return
}
defer dao.Close() // 程序退出关闭数据库连接
// 模型绑定
dao.DB.AutoMigrate(&models.Todo{})
// 注册路由
r := routers.SetupRouter()
if err := r.Run(fmt.Sprintf(":%d", setting.Conf.Port)); err != nil {
fmt.Printf("server startup failed, err:%v\n", err)
}
}