package main
import (
"fmt"
"gitea.party/public-messag-service/config"
"gitea.party/public-messag-service/config/app_ser"
"gitea.party/public-messag-service/config/app_ser/component"
"gitea.party/public-messag-service/docs"
_ "gitea.party/public-messag-service/docs"
mysql "gitea.party/public-messag-service/internal/models"
"gitea.party/public-messag-service/router"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"os"
)
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,
}
webRouter.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
docs.SwaggerInfo.Title = "短信、邮件服务 client API"
docs.SwaggerInfo.Description = "通用请求参数说明
"
docs.SwaggerInfo.Description += "api_key_id: 请求凭证 必填,string
"
//docs.SwaggerInfo.Description += " + credential.did: 会员设备ID 必填,int64
"
docs.SwaggerInfo.Description += "header: 请求附加头信息 可选,object
"
docs.SwaggerInfo.Description += " + header.version: 协议版本信息 可选,string
"
// 解析配置
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)
}