package statg import ( "stat/common/config" "stat/common/enum/consts" "stat/common/httputil" "stat/common/log" "github.com/dchest/captcha" ) var ( Conf GlobalConfig ProxyCfg *httputil.ProxyCfg VerifyIMGStore captcha.Store Tgbotsend string ) type ChartsConfig struct { Width int `json:"width"` Height int `json:"height"` } type GlobalConfig struct { ServerIndex ServerIndex `json:"serverIndex"` //1:麻豆,2:逼哩,3:知乎 RunMod consts.RunMod `json:"runMod"` Pprof bool `json:"pprof"` JwtKey string `json:"jwtKey"` InnerKey string `json:"innerKey"` InnerServers map[ServerIndex]string `json:"innerServers"` Kafka struct { Url string `json:"url"` Group string `json:"group"` } `json:"kafka"` Mongo struct { Url string `json:"url"` } `json:"mongo"` Redis struct { Url string `json:"url"` } `json:"redis"` Limit struct { Ip struct { Capacity int64 `json:"capacity"` Rate int64 `json:"rate"` } `json:"ip"` } `json:"limit"` URL struct { PackageUrl string `json:"packageUrl"` BiliPackageUrl string `json:"biliPackageUrl"` HuanqiuPackageUrl string `json:"huanqiuPackageUrl"` ManhuaPackageUrl string `json:"manhuaPackageUrl"` } `json:"url"` ProxyUrl struct { File string `json:"file"` FileRes string `json:"fileRes"` } `json:"proxyUrl"` KafkaServer bool `json:"kafkaServer"` Host string `json:"host"` Port int `json:"port"` IsVersion bool `json:"versionServer"` ImgUploadUrl string `json:"imgUploadUrl"` LandPageCDN string `json:"landPageCDN"` BotConfig BotConfig `json:"botConfig"` TgbotSend string `json:"tgbotSend"` ApkGenEnable bool `json:"apkGenEnable"` ChartsConfig ChartsConfig `json:"chartsConfig"` AppConfig Endpoints `json:"appConfig"` } func LoadConfig(path string) error { err := config.LoadJSON(path, &Conf) if err != nil { log.Fatal("加载本地配置失败", log.E(err)) return err } // set default value if Conf.Limit.Ip.Capacity <= 0 { Conf.Limit.Ip.Capacity = 300 } if Conf.Limit.Ip.Rate <= 0 { Conf.Limit.Ip.Rate = 5 } if Conf.ChartsConfig.Width <= 0 { Conf.ChartsConfig.Width = 1600 } if Conf.ChartsConfig.Height <= 0 { Conf.ChartsConfig.Height = 400 } Tgbotsend = Conf.TgbotSend // app config GlobalEndpoints = Conf.AppConfig for _, item := range GlobalEndpoints { GlobalIndexEndpoints[item.OwnerIndex] = append(GlobalIndexEndpoints[item.OwnerIndex], item) GlobalAppIdEndpoints[item.AppId] = item } return nil }