feat:完善项目
This commit is contained in:
75
cmd/serve/serve.go
Normal file
75
cmd/serve/serve.go
Normal file
@ -0,0 +1,75 @@
|
||||
package serve
|
||||
|
||||
import (
|
||||
"SciencesServer/app"
|
||||
"SciencesServer/app/common"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/cron"
|
||||
"SciencesServer/lib"
|
||||
"SciencesServer/router"
|
||||
"SciencesServer/rpc/client"
|
||||
"SciencesServer/serve/cache"
|
||||
"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() {
|
||||
// 载入配置
|
||||
lib.LoadConfig(this.Option.Config, config.SettingInfo, func(i interface{}) {
|
||||
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()
|
||||
})
|
||||
lib.LoadConfig(this.Option.RpcConfig, config.RPCServerSettingInfo, func(i interface{}) {
|
||||
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()
|
||||
orm.Init()
|
||||
task.Init()
|
||||
common.Init()
|
||||
cron.Init()
|
||||
app.Init()
|
||||
tools.Init()
|
||||
// 开启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}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user