package global import ( global "Panel_development/configs" ) // 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 int `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"` } type Swagger struct { Enable string `json:"enable"` } var ( DatabaseSetting *DatabaseSettingS NatsSetting *Nats JwtSetting *Jwt ServerSetting *ServerSettingS SubMailSetting *SubMail RedisSetting *Redis SwaggerSetting *Swagger ) // 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) err = s.ReadSection("Swagger", &SwaggerSetting) if err != nil { return err } return nil }