package config import ( "encoding/json" "fmt" "github.com/caarlos0/env/v6" "gitlab.finogeeks.club/finclip-backend/apm" "gitlab.finogeeks.club/finclip-backend/rmconf" ) const ( ENV_FDEP = "mop-fdep" ENV_UAT = "mop-uat" ENV_PRIVATE = "mop-private" ENV_COMMUNITY = "mop-community" ) var Cfg *Config func init() { Cfg = new(Config) if err := env.Parse(Cfg); err != nil { fmt.Printf("%+v\n", err) panic(err) } if Cfg.ConsulHttpIp != "" { Cfg.ConsulAddr = Cfg.ConsulHttpIp + ":" + Cfg.ConsulPort } else { Cfg.ConsulAddr = "" } if Cfg.RemoteConfAddr != "" && Cfg.ConsulKVConfigPath != "" { err := rmconf.StartConsulConfig(Cfg, Cfg.ConsulKVConfigPath, Cfg.ServerName, Cfg.RemoteConfAddr) if err != nil { fmt.Printf("StartConsulConfig error %+v\n", err) panic(err) } } b, _ := json.MarshalIndent(Cfg, "", " ") fmt.Println("config:", string(b)) apm.BuildApmClient(apm.CreateBuild(Cfg.SkyWalkingUrl, Cfg.ServerName, Cfg.SkyWalkingPartitions, Cfg.SkyWalkingEnable)) } func GetConfig() *Config { return Cfg } func IsPrivateEnv() bool { return Cfg.PublishEnv == "mop-private" } type Config struct { HttpPort string `env:"HTTP_PORT" envDefault:"8080"` GrpcPort string `env:"GRPC_PORT" envDefault:"9090"` ConsulAddr string `env:"CONSUL_ADDR" envDefault:""` ConsulHttpIp string `env:"CONSUL_HTTP_IP" envDefault:""` ConsulPort string `env:"CONSUL_PORT" envDefault:"8500"` ConsulTag string `env:"CONSUL_TAG" envDefault:"mop-finstore"` DebugLog bool `env:"DEBUG_LOG" envDefault:"true"` //是否打开debug模式 TraceLog bool `env:"TRACE_LOG" envDefault:"false"` //是否打开trace模式 Mode string `env:"MODE" envDefault:""` LogMode string `env:"LOG_MODE" envDefault:"debug"` OpenLogColor bool `env:"OPEN_LOG_COLOR" envDefault:"false"` ReqType string `env:"REQ_TYPE" envDefault:"http"` MongoURL string `env:"MONGO_URL" envDefault:""` MongoMode string `env:"MONGO_MODE" envDefault:"strong"` NetdiskHost string `env:"NETDISK_HOST" envDefault:"http://netdisk:9999"` NetdiskInternalDownloadUrl string `env:"NETDISK_INTERNAL_DOWNLOAD_URL" envDefault:"/api/v1/netdisk/download/"` //内网下载 NetdiskDownloadURLPrefix string `env:"NETDISK_DOWNLOAD_URL_PREFIX" envDefault:"/api/v1/netdisk/download/"` NetdiskUploadURL string `env:"NETDISK_UPLOAD_URL" envDefault:"/api/v1/netdisk/upload/mop?type=file&content={}"` EntryURL string `env:"ENTRY_URL" envDefault:""` OpenPurchAuth bool `env:"OPEN_PURCH_AUTH" envDefault:"false"` OpenFixOld bool `env:"OPEN_FIX_OLD" envDefault:"false"` ContactServer string `env:"CONTACT_SERVER" envDefault:""` DBName string `env:"DB_NAME" envDefault:"finstore-backend"` LogLevel string `env:"LOG_LEVEL" envDefault:"info"` LogFile string `env:"LOG_FILE" envDefault:""` LogBTLevel string `env:"LOG_BT_LEVEL" envDefault:"error"` LogBTEnabled bool `env:"LOG_BT_ENABLED" envDefault:"true"` LogJSONFormat bool `env:"LOG_JSON_FORMAT" envDefault:"false"` LogMaxSize int `env:"LOG_MAX_SIZE" envDefault:"100"` LogMaxAge int `env:"LOG_MAX_AGE" envDefault:"0"` LogMaxBackups int `env:"LOG_MAX_BACKUPS" envDefault:"10"` LogLocalTime bool `env:"LOG_LOCAL_TIME" envDefault:"true"` LogCompress bool `env:"LOG_COMPRESS" envDefault:"false"` IsPrivate bool `env:"IS_PRIVATE" envDefault:"true"` CheckMarket bool `env:"CHECK_MARKET" envDefault:"false"` SpecifyAppID bool `env:"SPECIFY_APPID" envDefault:""` HomeServerURL string `env:"HOMESERVER_URL" envDefault:""` Domain string `env:"DOMAIN" envDefault:""` MessageLimit int `env:"MESSAGE_LIMIT" envDefault:"500"` KeycloakHost string `env:"KEYCLOAK_HOST" envDefault:""` KeycloakClientID string `env:"KEYCLOAK_CLIENT_ID" envDefault:""` KeycloakClientSecret string `env:"KEYCLOAK_CLIENT_SECRET" envDefault:""` KeycloakUsername string `env:"KEYCLOAK_USERNAME" envDefault:""` KeycloakPassword string `env:"KEYCLOAK_USERNAME" envDefault:""` KeycloakRealm string `env:"KEYCLOAK_REALM" envDefault:""` IAMEnabled bool `env:"IAM_ENABLED" envDefault:"false"` IndustryContactHost string `env:"INDUSTRY_CONTACT_HOST" envDefault:""` BotCenterHost string `env:"BOT_CENTER_HOST" envDefault:""` AccountProviderURL string `env:"ACCOUNT_PROVIDER_URL" envDefault:""` GroupInfoProviderURL string `env:"GROUP_INFO_PROVIDER_URL" envDefault:""` PersonInfoProviderURL string `env:"PERSON_INFO_PROVIDER_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/organ/person/info/"` AccountInfoURL string `env:"ACCOUNT_INFO_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/organ/account/info/"` AccountSearchURL string `env:"ACCOUNT_SEARCH_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/organ/account/search/"` AdminAccountInfoUrl string `env:"ADMIN_ACCOUNT_INFO_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/operation/worker/detail/"` NotificationProviderURL string `env:"NOTIFICATION_PROVIDER_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/organ/business/info/"` AddLimitInfoURL string `env:"Add_LIMIT_INFO_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/operation/limit/add"` //调用账号模块申请权限 PayAddLimitHost string `env:"PAY_Add_LIMIT_HOST" envDefault:"http://mop-purchasing-rights-manager:8080"` PayAddLimitURL string `env:"PAY_Add_LIMIT_URL" envDefault:"/api/v1/mop/mop-purchasing-rights-manager/rights/apply"` //调用支付模块申请权限 PayUpdateLimitURL string `env:"PAY_UPDATE_LIMIT_URL" envDefault:"/api/v1/mop/mop-purchasing-rights-manager/rights/update"` //调用支付模块更新权限 PayCheckIdStatusURL string `env:"PAY_CHECK_STATUS_URL" envDefault:"/api/v1/mop/mop-purchasing-rights-manager/rights/business/status"` PayFixOldDataURL string `env:"PAY_FIX_DATA_URL" envDefault:"/api/v1/mop/mop-purchasing-rights-manager/history/rights/process"` GetRoleURL string `env:"GET_ROLE_URL" envDefault:""` NotificationURL string `env:"NOTIFICATION_URL" envDefault:""` SDKVersion string `env:"SDK_VERSION" envDefault:"3"` MOPDomainURL string `env:"MOP_DOMAIN_URL" envDefault:""` MOPDomainURLV2 string `env:"MOP_DOMAIN_URL_v2" envDefault:"http://mop-domain-manager:8080/api/v1/mop/applets-ecol-domain/oper/internal/all"` IsMOP bool `env:"IS_MOP" envDefault:"true"` KafkaVersion string `env:"KAFKA_VERSION" envDefault:"2.3.0"` KafkaAddr string `env:"KAFKA_ADDR" envDefault:"kafka-service.kafka:9093"` KafkaUser string `env:"KAFKA_USER" envDefault:""` KafkaPwd string `env:"KAFKA_PWD" envDefault:""` KafkaMechanism string `env:"KAFKA_MECHANISM" envDefault:"PLAIN"` KafkaDataLogTopic string `env:"OPERATE_LOG_TOPIC" envDefault:"mop_operation_log"` KafkaNotifyTopic string `env:"NOTIFY_DATA_TOPIC" envDefault:"mop_notify_data_topic"` KafkaTamTopic string `env:"TAM_DATA_TOPIC" envDefault:"mop_topic_tam_report_msg"` DBMode string `env:"DB_MODE" envDefault:"mongo"` //数据库模式 MysqlUrl string `env:"MYSQL_URL" envDefault:"root:finoTest@tcp(mysql.mysql:3306)/finclip_common?charset=utf8mb4"` DriverName string `env:"DRIVER_NAME" envDefault:"mysql"` OpenKafkaLog bool `env:"OPEN_KAFKA_LOG" envDefault:"false"` //日志是否输入kafka LogTopic string `env:"LOG_TOPIC" envDefault:"elk-log"` //日志输入kafka的topic RedisAddr string `env:"REDIS_ADDR" envDefault:""` RedisPassword string `env:"REDIS_PASSWORD" envDefault:""` RedisMode string `env:"REDIS_MODE" envDefault:"single"` RedisExpireTime int `env:"REDIS_EXPIRE_TIME" envDefault:"600"` RedisTrialExpireTime int `env:"REDIS_TRIAL_EXPIRE_TIME" envDefault:"300"` QRcodeExpireTime int `env:"QRCODE_EXPIRE_TIME" envDefault:"21600"` //临时二维码过期时间,单位:s ReviewQRcodeExpireTime int `env:"REVIEW_QRCODE_EXPIRE_TIME" envDefault:"180"` //审核二维码过期时间,单位:s QRcodeUri string `env:"QRCODE_URI" envDefault:"/api/v1/mop/runtime/applet/"` QRcodeUriV2 string `env:"QRCODE_URI_V2" envDefault:"/api/v2/mop/runtime/applet/"` AppSecretSalt string `env:"APP_SECRET_SALT" envDefault:""` AppSecretExpireTime int `env:"APP_SECRET_EXPIRE_TIME" envDefault:"600"` AppCheckWhiteSig string `env:"APP_CHECK_WHITE_SIG" envDefault:""` ZipKinUrl string `env:"ZIPKIN_URL" envDefault:""` ZipKinSToS bool `env:"ZIPKIN_STOS" envDefault:"false"` //是否依赖其他服务,涉及跟踪span的依赖关系,废弃 ServerName string `env:"SERVER_NAME" envDefault:"mop-app-manage-svr"` PublishEnv string `env:"PUB_ENV" envDefault:"mop-uat"` RuleEngineHost string `env:"RULE_ENGINE_HOST" envDefault:"http://mop-rule-engine-svr:8080"` PubNotifyRuleEngineURL string `env:"PUB_NOTIFY_RULE" envDefault:"/api/v1/mop/rule-engine/internal/pub-notify"` GetUserAuthURL string `env:"GET_USER_AUTH_URL" envDefault:"/api/v1/mop/rule-engine/internal/groups/user-auth"` EncryType string `env:"ENCRY_TYPE" envDefault:"MD5"` RedisSentinelAddr string `env:"REDIS_SENTINEL_ADDR" envDefault:"redis://redis-cluster-redis-cluster-sentinel.redis-cluster:26379/"` RedisMasterName string `env:"REDIS_MASTER_NAME" envDefault:"mymaster"` RedisDatabase int `env:"REDIS_INDEX" envDefault:"0"` RedisSentinelPassword string `env:"REDIS_SENTINEL_PASSWORD" envDefault:""` AppMemCount int `env:"APP_MEM_COUNT" envDefault:"4096"` SkyWalkingUrl string `env:"SKYWALKING_URL" envDefault:"127.0.0.1:11800"` SkyWalkingEnable bool `env:"SKYWALKING_ENABLE" envDefault:"false"` SkyWalkingPartitions uint32 `env:"SKYWALKING_PARTITIONS" envDefault:"1"` AppletBuildManageHost string `env:"APPLET_BUILD_MANAGE_HOST" envDefault:"http://mop-applet-build-manager:8080"` SdkVerJudgeUrl string `env:"SDKVER_JUDGE_URL" envDefault:"/api/v1/mop/mop-applet-build-manager/builds/encrypted/check"` GetAppletInfoUrl string `env:"GetAPPLET_INFO_URL" envDefault:"/api/v1/mop/mop-applet-build-manager/builds"` GetAppletInfoByIdUrl string `env:"GetAPPLET_INFO_BY_ID_URL" envDefault:"/api/v1/mop/mop-applet-build-manager/build-info/by-id"` OpenCdn bool `env:"OPEN_CDN" envDefault:"false"` CheckOrganIsExpiredUrl string `env:"CHECK_ORGAN_EXPIRED_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/operation/is-expired/organ"` //阿里云配置 AliyunKeyId string `env:"ALIYUN_KEY_ID" envDefault:"LTAI4GJpmYfsnuH76uJvPbvC"` AliyunKeySecret string `env:"ALIYUN_KEY_SECRET" envDefault:"oZ8ROGP6DjzyteRcGvUqKLpPEUZTNV"` AliyunRegionId string `env:"ALIYUN_REGION_ID" envDefault:"cn-hangzhou"` DnsIp string `env:"DNS_IP" envDefault:""` //默认ip UnicomDnsIp string `env:"UNICOM_DNS_IP" envDefault:""` //联通ip TelecomDnsIp string `env:"TELECOM_DNS_IP" envDefault:""` //电信ipip MobileDnsIp string `env:"MOBILE_DNS_IP" envDefault:""` //移动ip AliyunMainDomain string `env:"ALIYUN_MAIN_DOMAIN" envDefault:""` //阿里云主域名 AliyunMainDomainPrefix string `env:"ALIYUN_MAIN_DOMAIN_PREFIX" envDefault:""` //阿里云主域名前缀 AliyunMainDomainSuffix string `env:"ALIYUN_MAIN_DOMAIN_SUFFIX" envDefault:""` //阿里云主域名后缀 RemoteConfAddr string `env:"REMOTE_CONF_ADDR" envDefault:""` ConsulKVConfigPath string `env:"CONSUL_KV_CONFIG_PATH" envDefault:""` // kv path, 拼接得到public和服务配置的key ApiServer string `env:"API_SERVER" envDefault:""` ApmServer string `env:"APM_SERVER" envDefault:""` AuthExpireInterval int `env:"AUTH_EXPIRE_INTERVAL" envDefault:"1"` SmsServerHost string `env:"SMS_SERVER_HOST" envDefault:"http://mop-sms-server:8080"` // 下面两个环境变量也是定义api管控的开关, 注意app-manager-svr与rule-engine-server同步修改 SdkManagerHost string `env:"SMS_MANAGER_HOST" envDefault:"http://mop-sdk-manager:8080"` SdkManagerApiInfo string `env:"SMS_MANAGER_API_INFO" envDefault:""` // /api/v1/mop/mop-sdk-manager/organ/sdkApi/organInfo SpiderHost string `env:"SPIDER_HOST" envDefault:"http://mop-app-spider:8080"` SpiderNotifyPath string `env:"SPIDER_NOTIFY_URL" envDefault:"/api/v1/mop/app-spider/update-app"` SpiderPubAppNotifyURL string `env:"SPIDER_PUB_APP_NOTIFY_URl" envDefault:"/api/v1/mop/app-spider/page-spider"` SpiderUpdateAppMsg string `env:"SPIDER_UPDATE_APP_MSG" envDefault:"/api/v1/mop/app-spider/history-app"` SpiderUpdateBundleForbiddenURL string `env:"SPIDER_UPDATE_BUNDLE_FORBIDDEN_URL" envDefault:"/api/v1/mop/app-spider/update-bind-forbidden"` AppStatusChangeInfoTopic string `env:"APP_STATUS_CHANGE_INFO_TOPIC" envDefault:"mop_app_status_change_topic"` AppStatusChangeInfoChannel string `env:"APP_STATUS_CHANGE_INFO_CHANNEL" envDefault:"mop_app_status_change_channel"` CheckAppVerLimit int `env:"CHECK_APP_VER_LIMIT" envDefault:"3"` QRcodeGetAppVerInfoUrl string `env:"QRCODE_GET_APPVER_INFO_URL" envDefault:"/runtime/refresh/qrcode/"` ManageAppDevCount int `env:"MANAGE_APP_DEV_COUNT" envDefault:"20"` CodePackageNumLimit int `env:"CODE_PACKAGE_NUM_LIMIT" envDefault:"20"` BuildDbName string `env:"BUILD_DB_NAME" envDefault:"applets_build"` //金易联 SwanReportEnable bool `env:"SWAN_REPORT_ENABLE" envDefault:"false"` SwanHost string `env:"SWAN_HOST" envDefault:"https://swan.finogeeks.club"` SwanAppKey string `env:"SWAN_APP_KEY" envDefault:"V1eSG6lAg6PB4VhJ509AMgPR5OTw0JA"` SwanAppSecret string `env:"SWAN_APP_SECRET" envDefault:"R0DWiCTJK7ZpHXKOqqZ3I5fyqFarDRE"` AppTagTypeList string `env:"APP_TAG_TYPE_LIST" envDefault:"证券开户,投顾行情,投教研报,生活服务,政务教育,资讯行情,电子商务,工业互联网,物联网,其他"` ConfigManagerHost string `env:"CONFIG_MANAGER_HOST" envDefault:"http://mop-control-manager:8080"` GetAppTagConfigUrl string `env:"GET_APP_TAG_CONFIG_URL" envDefault:"/api/v1/mop/mop-control-manager/mopHelper/config/info"` UatDomainList []string `env:"UAT_DOMAIN_LIST" envDefault:"https://www.finclip.com,https://www.finclip.com,https://finclip.com,https://finclip.com/"` WechatInfoURL string `env:"WECHAT_INFO_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/wechat/info/"` UpsertWeChatInfoURL string `env:"UPSERT_WECHAT_INFO_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/wechat/info"` WechatLoginInfoURL string `env:"WECHAT_LOGIN_INFO_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/wechat-login/"` DataCounterHost string `env:"DATA_COUNTER_HOST" envDefault:"http://finclip-data-counter:8080"` TouchWechatInfoURL string `env:"TOUCH_WECHAT_INFO_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/wechat/touch_info/"` DeleteWechatQrcodeURL string `env:"DELETE_WECHAT_QRCODE_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/wechat/qrcode/delete"` HintDotResetURL string `env:"HINT_DOT_RESET_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/read_dot/reset"` IsTrialHasReadURL string `env:"IS_TRIAL_HAS_READ_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/read_dot/is_read"` ReadTrialQrURL string `env:"READ_TRIAL_QR_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/read_dot/read_trial_qr"` IsShowHintURL string `env:"IS_SHOW_HINT_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/read_dot/is_show_hint"` ReadWechatHintURL string `env:"READ_WECHAT_HINT_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/wechat/read_hint"` GetAppByWechatURL string `env:"GET_APP_BY_WECHAT_URL" envDefault:"http://finclip-app-ext-svr:8080/api/v1/mop/finclip-app-ext-svr/openapi/wechat/app"` AddNotifyURL string `env:"ADD_NOTIFY_URL" envDefault:"http://mop-notify:8080/api/v1/mop/applets-ecol-notify/add"` AuditDelaySmsURL string `env:"AUDIT_DELAY_SMS_URL" envDefault:"http://mop-audit-manage-svr:8080/api/v1/mop/mop-audit-manage-svr/organ/delay-sms"` AddAvailableBundleNum int `env:"ADD_AVAILABLE_BUNDLE_NUM" envDefault:"2"` AddALLBundleNum int `env:"ADD_ALL_BUNDLE_NUM" envDefault:"10"` IsHcc bool `env:"IS_HCC" envDefault:"false"` HccEnv string `env:"HCC_ENV" envDefault:"uat"` IsOpenAuditSecurity bool `env:"IS_OPEN_AUDIT_SECURITY" envDefault:"false"` OrganListURL string `env:"ORGAN_LIST_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/operation/organlist"` BindLimitURL string `env:"BIND_LIMIT_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/organ/limit/binding"` MiniProgramSearchURL string `env:"MINI_PROGRAM_SEARCH_URL" envDefault:"http://mop-miniprogram-preview:8080/miniprogram/search"` ThirdEnv string `env:"THIRD_ENV" envDefault:""` SmsGateWayUrl string `env:"SMS_GATEWAY_URL" envDefault:"http://mop-verify-code-gateway:8080/api/v1/mop/verifycode-server/phone/third/sms"` MonitorPort string `env:"MONITOR_PORT" envDefault:"9092"` //监控端口 OpenMonitor bool `env:"OPEN_MONITOR" envDefault:"false"` //是否打开监控 GetAuditDataInfoByBuildInfoIdUrl string `env:"GET_AUDIT_DATA_INFO_BY_BUILD_INFO_ID_URL" envDefault:"http://finclip-security-audit:8080/api/v1/mop/finclip-security-audit/audit/info/by/build-info-id"` GetIsOrganAdminURL string `env:"GET_IS_ORGAN_ADMIN_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/organ/is-admin/by-phone"` GetIsOrganCreatorURL string `env:"GET_IS_ORGAN_CREATOR_URL" envDefault:"http://mop-account-system:8080/api/v1/mop/applets-ecol-account/organ/is-creator/by-phone"` } func (c *Config) IsPrivateEnv() bool { return c.PublishEnv == ENV_PRIVATE } func (c *Config) IsFdepEnv() bool { return c.PublishEnv == ENV_FDEP } func (c *Config) IsUatEnv() bool { return c.PublishEnv == ENV_UAT } func (c *Config) IsCommunityEnv() bool { return c.PublishEnv == ENV_COMMUNITY } func (c *Config) EnableApiManage() bool { // 如果填写SdkManagerApiInfo, 则认为当前环境开启了api管理 return c.SdkManagerApiInfo != "" }