zhangzengfei
2024-04-24 cc8263fb876b44a25960bc553ed13b9fbbef18e6
config/config.go
@@ -16,6 +16,20 @@
   Password string `mapstructure:"password"`
}
type client struct {
   DeviceID          string `mapstructure:"device-id"`
   Username          string `mapstructure:"username"`
   Password          string `mapstructure:"password"`
   ServerAddr        string `mapstructure:"server-addr"`
   ServerPort        string `mapstructure:"server-port"`
   Proto             string `mapstructure:"proto" `             // http, https
   UploadType        string `mapstructure:"upload-type"`        // binary, url
   ChannelNo         string `mapstructure:"channel-number"`     // 通道号, 同id
   HeartbeatInterval int    `mapstructure:"heartbeat-interval"` // 心跳周期
   HeartbeatCount    int    `mapstructure:"heartbeat-count"`    // 心跳超时次数
   Enable            bool   `mapstructure:"enable"`
}
type logConfig struct {
   LogWay string `mapstructure:"log-way"` // 日志输出
   Path   string `mapstructure:"path"`    // 日志存储路径
@@ -29,6 +43,7 @@
   ReportInterval int    `mapstructure:"report-interval"`
   RetryInterval  int    `mapstructure:"retry-interval"`
   CutFaceImage   bool   `mapstructure:"cut-face-image"`
   Enable         bool   `mapstructure:"enable"`
}
type rateLimitConfig struct {
@@ -40,6 +55,7 @@
var LogConf = &logConfig{}
var ForwardConf = &forward{}
var RateLimitConf = &rateLimitConfig{}
var ClientConf = &client{}
// Init is an exported method that takes the environment starts the viper
// (external lib) and returns the configuration struct.
@@ -67,6 +83,7 @@
   v.UnmarshalKey("log", LogConf)
   v.UnmarshalKey("forward", ForwardConf)
   v.UnmarshalKey("rate-limit", RateLimitConf)
   v.UnmarshalKey("client", ClientConf)
   if LogConf.Level == "" {
      LogConf.Level = "info"