2021-09-28 11:47:19 +08:00
|
|
|
|
package serve
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"SciencesServer/app"
|
|
|
|
|
"SciencesServer/app/common"
|
|
|
|
|
"SciencesServer/config"
|
|
|
|
|
"SciencesServer/cron"
|
|
|
|
|
"SciencesServer/router"
|
|
|
|
|
"SciencesServer/rpc/client"
|
|
|
|
|
"SciencesServer/serve/cache"
|
2021-10-15 17:31:23 +08:00
|
|
|
|
"SciencesServer/serve/es"
|
2021-09-28 11:47:19 +08:00
|
|
|
|
"SciencesServer/serve/logger"
|
|
|
|
|
"SciencesServer/serve/orm"
|
|
|
|
|
"SciencesServer/serve/web"
|
|
|
|
|
"SciencesServer/task"
|
|
|
|
|
"SciencesServer/tools"
|
|
|
|
|
"SciencesServer/utils"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Serve struct {
|
|
|
|
|
*Option
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Option struct {
|
|
|
|
|
Config string `json:"config"`
|
|
|
|
|
RpcConfig string `json:"rpc_config"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *Serve) Run() {
|
|
|
|
|
// 载入配置
|
2021-12-03 15:22:23 +08:00
|
|
|
|
utils.LoadConfig(this.Option.Config, config.SettingInfo, func(i interface{}) {
|
2021-09-28 11:47:19 +08:00
|
|
|
|
obj := i.(*config.Setting)
|
|
|
|
|
obj.Upload.Exts = strings.Split(obj.Upload.Ext, ",")
|
|
|
|
|
logger.NewLogger().Init(&logger.Option{File: obj.Log.File, LeastDay: obj.Log.LeastDay, Level: obj.Log.Level, IsStdout: false}).Load()
|
|
|
|
|
})
|
2021-12-03 15:22:23 +08:00
|
|
|
|
utils.LoadConfig(this.Option.RpcConfig, config.RPCServerSettingInfo, func(i interface{}) {
|
2021-09-28 11:47:19 +08:00
|
|
|
|
obj := i.(*config.RPCServerSetting)
|
|
|
|
|
go utils.TryCatch(func() {
|
|
|
|
|
options := make(map[string]*client.ServerOption, 0)
|
|
|
|
|
|
|
|
|
|
for k, v := range obj.Servers {
|
|
|
|
|
options[k] = &client.ServerOption{
|
|
|
|
|
Host: v.Host, Port: v.Port, IsTLS: v.IsTLS, TLSName: v.TLSName, Pem: v.Pem,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
client.NewServer(options).Run()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
cache.Init()
|
2021-12-03 11:32:26 +08:00
|
|
|
|
//orm.Init()
|
|
|
|
|
// TODO:待优化完善
|
|
|
|
|
orm.NewInstance(
|
|
|
|
|
orm.WithDebug(config.SettingInfo.Engine.Debug),
|
|
|
|
|
orm.WithDBMode(config.SettingInfo.Engine.DBMode),
|
2021-12-03 15:22:23 +08:00
|
|
|
|
orm.WithTablePrefix(config.SettingInfo.Engine.TablePrefix),
|
|
|
|
|
orm.WithSingularTable(!config.SettingInfo.Engine.Complex),
|
|
|
|
|
orm.WithMaxIdleConns(config.SettingInfo.Engine.MaxIdleConns),
|
|
|
|
|
orm.WithMaxOpenConns(config.SettingInfo.Engine.MaxOpenConns),
|
|
|
|
|
orm.WithMaxLifetime(config.SettingInfo.Engine.MaxLifetime),
|
2021-12-03 11:32:26 +08:00
|
|
|
|
//orm.WithMysqlUser(config.SettingInfo.Engine.Mysql.User),
|
|
|
|
|
).Init()
|
2021-09-28 11:47:19 +08:00
|
|
|
|
task.Init()
|
|
|
|
|
common.Init()
|
|
|
|
|
cron.Init()
|
|
|
|
|
app.Init()
|
|
|
|
|
tools.Init()
|
2021-10-15 17:31:23 +08:00
|
|
|
|
// 开启Elasticsearch
|
|
|
|
|
es.NewEs()(&es.EsConfig{Address: []string{"http://192.168.0.188:9200"}}).Run()
|
2021-09-28 11:47:19 +08:00
|
|
|
|
// 开启web
|
|
|
|
|
web.NewWeb()(&web.WebConfig{
|
|
|
|
|
Port: config.SettingInfo.Server.Port, ReadTimeout: config.SettingInfo.Server.ReadTimeout,
|
|
|
|
|
WriteTimeout: config.SettingInfo.Server.WriteTimeout, IdleTimeout: config.SettingInfo.Server.IdleTimeout,
|
|
|
|
|
}).Run(router.NewRouter(&router.Option{
|
|
|
|
|
Mode: gin.DebugMode, IsCors: true,
|
|
|
|
|
RateLimitConfig: &router.RateLimitConfig{
|
|
|
|
|
IsRate: true, Limit: config.SettingInfo.Rate.Limit, Capacity: config.SettingInfo.Rate.Capacity,
|
|
|
|
|
},
|
|
|
|
|
}).Init())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewServe() func(option *Option) *Serve {
|
|
|
|
|
return func(option *Option) *Serve {
|
|
|
|
|
return &Serve{option}
|
|
|
|
|
}
|
|
|
|
|
}
|