代码拉取完成,页面将自动刷新
package configx
import (
"encoding/json"
"fmt"
"gitee.com/fmpt/fmgo/filex"
"gitee.com/fmpt/fmgo/jwtx"
"gitee.com/fmpt/fmgo/logx"
"go.uber.org/zap/zapcore"
"os"
"os/signal"
"path/filepath"
"sync"
"syscall"
)
// ConfigAll 包含全部配置信息
type ConfigAll struct {
Config
BaseConfig
}
type Config struct {
Name string `json:"name"`
Version string `json:"version"`
Host string `json:"host"`
DataRoot string `json:"data_root"`
RelativeShutdownInfoFilePath string `json:"relative_shutdown_info_file_path"`
RelativeLogPath string `json:"relative_log_path"`
Env string `json:"env"`
Server string `json:"server"`
Jwt *jwtx.JwtMould
}
type BaseConfig struct {
sync.RWMutex
Database string `json:"database"`
CenterAddr string `json:"center_addr"`
DfsPort string `json:"dfs_port"`
StreamPort string `json:"stream_port"`
MqUserName string `json:"mq_user_name"`
MqPassword string `json:"mq_password"`
Redis string `json:"redis"`
TracingAddr string `json:"tracing_addr"`
RedisPassword string `json:"redis_password"`
UdpPort int32 `json:"udp_port"`
}
func Default() *Config {
return &Config{
DataRoot: ".",
Jwt: jwtx.DefaultJwt(),
}
}
func (c *Config) InitLog(level zapcore.Level) {
localPath, _ := filepath.Abs(filepath.Dir(os.Args[0]))
logPath := filepath.Join(localPath, c.RelativeLogPath)
logx.InitLogger(logPath, level)
}
func (c *Config) WriteShutdownPort(port int) error {
portMap := map[string]interface{}{"port": port, "version": c.Version}
buf, err := json.Marshal(portMap)
if err != nil {
return err
}
sdpPath := filepath.Join(c.DataRoot, c.RelativeShutdownInfoFilePath)
err = filex.WriteFile(sdpPath, buf, 0666)
if err != nil {
return err
}
return nil
}
func (c *Config) Listener() {
sign := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sign)
go func() {
for {
select {
case s := <-sign:
switch s {
case syscall.SIGINT, syscall.SIGTERM:
done <- true
}
}
}
}()
strInfo := fmt.Sprintf("service is running ...")
logx.Info(strInfo)
<-done
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。