76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"os"
|
|
"project/config"
|
|
"project/config/app_ser"
|
|
"project/config/app_ser/component"
|
|
mysql "project/internal/models"
|
|
"project/router"
|
|
)
|
|
|
|
func main() {
|
|
app := app_ser.Application{}
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
webRouter := gin.Default()
|
|
|
|
//cRedis := component.Redis{
|
|
// Clts: map[string]*component.RedisClient{"default": &redis.Default},
|
|
//}
|
|
|
|
var cMysql component.MySQL
|
|
cMysql = component.MySQL{
|
|
Clts: map[string]*component.MySQLClient{"ns9": &mysql.Ns9},
|
|
}
|
|
|
|
// 关联配置
|
|
ser := &app_ser.WebService{
|
|
BasicService: app_ser.BasicService{
|
|
InitBefore: func() error {
|
|
config.PrintfDSN = true
|
|
return nil
|
|
},
|
|
RunBefore: func() (err error) {
|
|
// 慢查询阈值
|
|
cMysql.Cfg.SlowThreshold = 500
|
|
|
|
// 初始化
|
|
//logs.Instance = app.Log
|
|
config.AppEnv = &app.Cfg
|
|
|
|
// init local cache
|
|
//if err = cache.Init(); err != nil {
|
|
// return err
|
|
//}
|
|
|
|
// 初始化
|
|
router.Router(webRouter)
|
|
return nil
|
|
},
|
|
},
|
|
Handler: webRouter,
|
|
}
|
|
|
|
// 解析配置
|
|
if err := ser.ParserFile(&config.FileCfg{
|
|
Listen: &ser.Cfg.Port,
|
|
RunMode: &ser.Cfg.RunMode,
|
|
Mysql: &mysql.Ns9.Cfg,
|
|
//Redis: &redis.Default.Cfg,
|
|
}); err != nil {
|
|
fmt.Printf("Init Error: %s", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
// 运行程序
|
|
app.Component = map[string]app_ser.Component{
|
|
"mysql": &cMysql,
|
|
//"redis": &cRedis,
|
|
//"cron": &cache.Default,
|
|
}
|
|
app.Start(nil, os.Args, ser)
|
|
}
|