by Robin at 20240524
This commit is contained in:
parent
3c694f7995
commit
248b93ced7
|
@ -57,9 +57,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化日志
|
// 初始化日志
|
||||||
fmt.Printf("cfg.oflineserver: %v", cfg.OfflineServer)
|
logger.InitLogger(*cfg.OfflineServerLog)
|
||||||
fmt.Printf("cfg.oflineserver.log: %v", cfg.OfflineServer.Log)
|
|
||||||
logger.InitLogger(*cfg.OfflineServer.Log)
|
|
||||||
|
|
||||||
// 初始化短信服务
|
// 初始化短信服务
|
||||||
err = sms.Init(cfg.Dysmsapi)
|
err = sms.Init(cfg.Dysmsapi)
|
||||||
|
@ -113,10 +111,13 @@ func main() {
|
||||||
validator.InitDefaultNotNullValidator()
|
validator.InitDefaultNotNullValidator()
|
||||||
controller.InitOffline(router)
|
controller.InitOffline(router)
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", GetIp(), cfg.OfflineServer.App.Port),
|
Addr: fmt.Sprintf("%s:%d", GetIp(), cfg.OfflineServerApp.Port),
|
||||||
Handler: router,
|
Handler: router,
|
||||||
}
|
}
|
||||||
httpserver.StartOfflineHttpServer(srv, cfg.OfflineServer)
|
httpserver.StartHttpServer(srv, &configcenter.DefaultConfig{
|
||||||
|
Log: *cfg.OfflineServerLog,
|
||||||
|
App: *cfg.OfflineServerApp,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintAndExit(msg string) {
|
func PrintAndExit(msg string) {
|
||||||
|
|
|
@ -4,23 +4,24 @@ import "service/library/configcenter"
|
||||||
|
|
||||||
type ConfigSt struct {
|
type ConfigSt struct {
|
||||||
*configcenter.DefaultConfig `yaml:",inline"` // default
|
*configcenter.DefaultConfig `yaml:",inline"` // default
|
||||||
MixMongo *configcenter.MongoConfig `json:"mix_mongo" yaml:"mix_mongo"` // mix mongo
|
MixMongo *configcenter.MongoConfig `json:"mix_mongo" yaml:"mix_mongo"` // mix mongo
|
||||||
MixMysql *configcenter.MysqlConfig `json:"mix_mysql" yaml:"mix_mysql"` // mix mysql
|
MixMysql *configcenter.MysqlConfig `json:"mix_mysql" yaml:"mix_mysql"` // mix mysql
|
||||||
Crypto *configcenter.CryptoConfig `json:"crypto" yaml:"crypto"` // 账号相关加密
|
Crypto *configcenter.CryptoConfig `json:"crypto" yaml:"crypto"` // 账号相关加密
|
||||||
Wxpay *configcenter.WxpayClientConfig `json:"wxpay" yaml:"wxpay"` // 微信支付
|
Wxpay *configcenter.WxpayClientConfig `json:"wxpay" yaml:"wxpay"` // 微信支付
|
||||||
WxpayTFZ *configcenter.WxpayClientConfig `json:"wxpay_tfz" yaml:"wxpay_tfz"` // 微信支付
|
WxpayTFZ *configcenter.WxpayClientConfig `json:"wxpay_tfz" yaml:"wxpay_tfz"` // 微信支付
|
||||||
Alipay *configcenter.AlipayClientConfig `json:"alipay" yaml:"alipay"` // 支付宝 心意到了
|
Alipay *configcenter.AlipayClientConfig `json:"alipay" yaml:"alipay"` // 支付宝 心意到了
|
||||||
AlipayMYTS *configcenter.AlipayClientConfig `json:"alipay_myts" yaml:"alipay_myts"` // 支付宝 觅缘天使
|
AlipayMYTS *configcenter.AlipayClientConfig `json:"alipay_myts" yaml:"alipay_myts"` // 支付宝 觅缘天使
|
||||||
Apollo *configcenter.ApolloConfig `json:"apollo" yaml:"apollo"` // Apollo
|
Apollo *configcenter.ApolloConfig `json:"apollo" yaml:"apollo"` // Apollo
|
||||||
Media *configcenter.MediaConfig `json:"media" yaml:"media"` // 媒体配置
|
Media *configcenter.MediaConfig `json:"media" yaml:"media"` // 媒体配置
|
||||||
Dysmsapi *configcenter.DysmsapiConfig `json:"dysmsapi" yaml:"dysmsapi"` // 阿里云短信服务
|
Dysmsapi *configcenter.DysmsapiConfig `json:"dysmsapi" yaml:"dysmsapi"` // 阿里云短信服务
|
||||||
ImageAudit *configcenter.ImageAuditConfig `json:"imageaudit" yaml:"imageaudit"` // 图片内容审核服务
|
ImageAudit *configcenter.ImageAuditConfig `json:"imageaudit" yaml:"imageaudit"` // 图片内容审核服务
|
||||||
RedisConfig *configcenter.RedisConfig `json:"redis" yaml:"redis"` // redis
|
RedisConfig *configcenter.RedisConfig `json:"redis" yaml:"redis"` // redis
|
||||||
ServerInfo *configcenter.ServerInfoConfig `json:"server_info" yaml:"server_info"` // 服务器信息
|
ServerInfo *configcenter.ServerInfoConfig `json:"server_info" yaml:"server_info"` // 服务器信息
|
||||||
TextAudit *configcenter.TextAuditConfig `json:"textaudit" yaml:"textaudit"` // 文字内容审核服务
|
TextAudit *configcenter.TextAuditConfig `json:"textaudit" yaml:"textaudit"` // 文字内容审核服务
|
||||||
XxlJob *configcenter.XxlJobConfig `json:"xxl_job" yaml:"xxl_job"` // xxl-job作业系统
|
XxlJob *configcenter.XxlJobConfig `json:"xxl_job" yaml:"xxl_job"` // xxl-job作业系统
|
||||||
DingTalkRobot *configcenter.DingTalkRobotConfig `json:"ding_talk_robot" yaml:"ding_talk_robot"` // 钉钉机器人
|
DingTalkRobot *configcenter.DingTalkRobotConfig `json:"ding_talk_robot" yaml:"ding_talk_robot"` // 钉钉机器人
|
||||||
VideoModeration *configcenter.VideoModerationConfig `json:"video_moderation" yaml:"video_moderation"` // 视频审核
|
VideoModeration *configcenter.VideoModerationConfig `json:"video_moderation" yaml:"video_moderation"` // 视频审核
|
||||||
ElasticSearch *configcenter.ElasticSearchConfig `json:"elastic_search" yaml:"elastic_search"` // es
|
ElasticSearch *configcenter.ElasticSearchConfig `json:"elastic_search" yaml:"elastic_search"` // es
|
||||||
OfflineServer *configcenter.OfflineServerConfig `json:"offline_server" yaml:"offline_server"` // 离线任务
|
OfflineServerLog *configcenter.LoggerConfig `json:"offline_server_log" yaml:"offline_server_log"` // 离线任务log
|
||||||
|
OfflineServerApp *configcenter.AppConfig `json:"offline_server_app" yaml:"offline_server_app"` // 离线任务app
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,15 +145,14 @@ elastic_search:
|
||||||
password: "Wishpal@2024"
|
password: "Wishpal@2024"
|
||||||
sniff: false
|
sniff: false
|
||||||
|
|
||||||
offline_server:
|
offline_server_log:
|
||||||
log:
|
|
||||||
stdout_enable: true
|
stdout_enable: true
|
||||||
stdout_level: "trace"
|
stdout_level: "trace"
|
||||||
file_enable: true
|
file_enable: true
|
||||||
file_level: "trace"
|
file_level: "trace"
|
||||||
file_abs_path: "/app/ironfan/log/offline-server/"
|
file_abs_path: "/app/ironfan/log/offline-server/"
|
||||||
|
|
||||||
app:
|
offline_server_app:
|
||||||
app_name: "offline-server"
|
app_name: "offline-server"
|
||||||
ip: "127.0.0.1"
|
ip: "127.0.0.1"
|
||||||
port: 9998
|
port: 9998
|
|
@ -173,12 +173,6 @@ type ElasticSearchConfig struct {
|
||||||
Sniff bool `json:"sniff" yaml:"sniff"` // sniffer
|
Sniff bool `json:"sniff" yaml:"sniff"` // sniffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// 离线机器配置
|
|
||||||
type OfflineServerConfig struct {
|
|
||||||
Log *LoggerConfig `json:"log" yaml:"log"` // 日志配置
|
|
||||||
App *AppConfig `json:"app" yaml:"app"` // 服务配置
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadConfig(configFilePath string, cfg interface{}) error {
|
func LoadConfig(configFilePath string, cfg interface{}) error {
|
||||||
cfgStr, err := ioutil.ReadFile(configFilePath)
|
cfgStr, err := ioutil.ReadFile(configFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -40,31 +40,3 @@ func StartHttpServer(srv *http.Server, cfg *configcenter.DefaultConfig) {
|
||||||
|
|
||||||
logger.Info("Server exited")
|
logger.Info("Server exited")
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartOfflineHttpServer(srv *http.Server, cfg *configcenter.OfflineServerConfig) {
|
|
||||||
go func() {
|
|
||||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
||||||
logger.Fatal("listen: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
logger.Info("Server %s start at %s", cfg.App.AppName, srv.Addr)
|
|
||||||
|
|
||||||
quit := make(chan os.Signal)
|
|
||||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
<-quit
|
|
||||||
logger.Info("Shutdown Server ...")
|
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
if err := srv.Shutdown(ctx); err != nil {
|
|
||||||
logger.Fatal("Server Shutdown:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
logger.Info("timeout of 1 seconds.")
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Info("Server exited")
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue