package global import ( global "project_management/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"` } // Qiniu qiniu type Qiniu struct { AccessKeyID string `json:"accessKeyID"` Endpoint string `json:"endpoint"` AccessKeySecret string `json:"accessKeySecret"` BucketName string `json:"bucketName"` } type ICon struct { IconPath string `json:"iconPath"` BackgroundImagePc string `json:"BackgroundImagePc"` BackgroundImageMobile string `json:"BackgroundImageMobile"` StartupDiagramPc string `json:"StartupDiagramPc"` StartupDiagramMobile string `json:"StartupDiagramMobile"` } var ( DatabaseSetting *DatabaseSettingS NatsSetting *Nats JwtSetting *Jwt ServerSetting *ServerSettingS SubMailSetting *SubMail RedisSetting *Redis SwaggerSetting *Swagger QiniuSetting *Qiniu IconSetting *ICon ) // 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) err = s.ReadSection("Qiniu", &QiniuSetting) err = s.ReadSection("ICon", &IconSetting) if err != nil { return err } return nil }