2025-04-30 16:04:32 +08:00

88 lines
2.2 KiB
Go

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