-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
54 lines (44 loc) · 1.19 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
package main
import (
"fmt"
"log"
"os"
"github.com/BurntSushi/toml"
"github.com/aoas/server/config"
"github.com/aoas/server/models"
"github.com/aoas/server/routers"
"github.com/aoas/server/utils"
)
func main() {
var conf config.Config
if _, err := toml.DecodeFile("./config.toml", &conf); err != nil {
log.Fatalf("invalid config file - %s", err.Error())
}
fmt.Println("origins :", conf.CORS.Origins)
// 创建数据库ORM
engine, err := models.CreateEngine(&conf)
if err != nil {
log.Fatalf("create database engine failed - %s", err.Error())
}
// 同步相间结构到数据库
if err := models.SyncTables(); err != nil {
log.Fatalf("sync model to database failed - %s", err.Error())
}
// 初始化日志
logFile, err := os.Create(conf.LogPath)
defer logFile.Close()
if err != nil {
log.Fatalf("Create log file failed - %s", err.Error())
}
logger := utils.NewSimpleLogger(logFile)
// 缓存用户及权限相关表
if conf.Database.EnableCache {
models.EnableCache()
}
router, err := routers.New(engine, conf, logger)
if err != nil {
log.Fatalf("init router failed - %s", err.Error())
}
// cors
router.Run(fmt.Sprintf("%s:%d", conf.App.Host, conf.App.Port))
}