package global import ( global "lot_interlligentControl/configs" "time" ) // DatabaseSettingS 数据库配置 type DatabaseSettingS struct { Dialect string `json:"dialect"` Host string `json:"host"` Port string `json:"port"` UserName string `json:"userName"` Password string `json:"password"` Db string `json:"db"` OtherParams string `json:"otherParams"` MaxIdleConn int `json:"max_idle_conn"` MaxOpenConn int `json:"max_open_conn"` ConnMaxLifetime string `json:"conn_max_lifetime"` } // Nats 配置 type Nats struct { NatsServerUrl string `json:"NatsServer_Url"` } // Jwt 配置 type Jwt struct { Secret string `json:"secret"` RefreshExpire time.Time `json:"refresh_expire"` Issuer string `json:"issuer"` } // ServerSettingS 服务器配置 type ServerSettingS struct { Mode string `json:"mode"` Port string `json:"port"` InsecureServingInfo string `json:"insecure_serving_info"` } type SubMail struct { Appid string `json:"appid"` Signature string `json:"signature"` } type Redis struct { Addr string `json:"addr"` Password string `json:"password"` DB int `json:"db"` } var ( DatabaseSetting *DatabaseSettingS NatsSetting *Nats JwtSetting *Jwt ServerSetting *ServerSettingS SubMailSetting *SubMail RedisSetting *Redis ) // SetupSetting 读取配置到全局变量 func SetupSetting() error { s, err := global.NewSetting() err = s.ReadSection("Database", &DatabaseSetting) err = s.ReadSection("Nats", &NatsSetting) err = s.ReadSection("Jwt", &JwtSetting) err = s.ReadSection("Server", &ServerSetting) err = s.ReadSection("SubMail", &SubMailSetting) err = s.ReadSection("Redis", &RedisSetting) if err != nil { return err } return nil }