123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- package utils
- import (
- "errors"
- "fmt"
- "strconv"
- beeLogger "github.com/beego/bee/v2/logger"
- "github.com/beego/beego/v2/server/web"
- "github.com/qiniu/qmgo"
- "github.com/spf13/viper"
- )
- var (
- RunMode string //运行模式
- MYSQL_URL string //数据库连接
- MYSQL_URL_RDDP string //数据库连接
- MYSQL_URL_EDB string
- MYSQL_URL_DATA string
- MYSQL_URL_GL string
- MYSQL_LOG_URL string
- MYSQL_WEEKLY_URL string //用户主库
- MYSQL_AI_URL string //ETA-AI 数据库
- MgoUrlData string // mongodb数据库连接配置
- REDIS_CACHE string //缓存地址
- //Rc *cache.Cache //redis缓存
- Re error //redis错误
- Rc RedisClient //redis缓存
- MgoDataCli *qmgo.Client // mongodb客户端连接
- MgoDataDbName string // mongodb指标数据的库名
- )
- // 基础配置
- var (
- STATIC_DIR string
- DesKey string // 接口返回加密KEY
- APPNAME string //项目中文名称
- EmailSendToUsers string // 邮件提醒人员
- JhGnAppKey string // 聚合短信,国内AppKey
- JhGjAppKey string // 聚合短信,国际AppKey
- ResourceProxyUrl string // 代理资源地址
- RESOURCE_DIR string
- )
- // ES配置
- var (
- ES_URL string // ES服务器地址
- ES_USERNAME string // ES账号
- ES_PASSWORD string // ES密码
- )
- // 公共api内部服务调用
- var (
- // EDB_LIB_URL 公共指标库
- EDB_LIB_URL string
- APP_EDB_LIB_NAME_EN string
- EDB_LIB_Md5_KEY string
- // PublicChartHost 公共图库的host
- PublicChartHost string
- // MySteelPostUrl 钢联化工的服务地址
- MySteelPostUrl string
- // SendWxTemplateMsgUrl 模板消息推送
- SendWxTemplateMsgUrl string
- // SendTemplateMsgAuthorization 模板推送秘钥
- SendTemplateMsgAuthorization string
- // HandleVideoDecibelUrl 处理音频分贝的url
- HandleVideoDecibelUrl string
- // Ppt2ImageUrl ppt转图片服务的地址
- Ppt2ImageUrl string
- // HongzeOpenApiHost 开放openapi的地址
- HongzeOpenApiHost string
- // EnglishShareUrl 英文研报群发邮件分享地址
- EnglishShareUrl string
- // EnPolicyReportUrl 英文策略报告
- EnPolicyReportUrl string
- // GoogleTranslateUrl 谷歌翻译服务
- GoogleTranslateUrl string
- // AlarmMsgUrl 报警服务地址
- AlarmMsgUrl string
- // ChatUrl chatGPT服务地址
- ChatUrl string
- EtaBridgeUrl string // 桥接服务地址
- EtaBridgeAppNameEn string // 桥接服务英文名称-鉴权用
- EtaBridgeMd5Key string // 桥接服务Md5密钥-鉴权用
- EtaBridgeDesKey string // 桥接服务Des密钥-解密数据用
- EtaBridgeLoginUrl string // 第三方登录鉴权接口地址
- EtaBridgeLogoutUrl string // 第三方登出接口地址
- ETAMiniBridgeUrl string // 桥接服务地址
- ETA_MINI_APPID string // 桥接服务-鉴权用
- ETA_MINI_APP_SECRET string // 桥接服务-鉴权用
- )
- // 微信配置信息
- var (
- WxId string //微信原始ID
- WxAppId string // 公众号appid
- WxAppSecret string // 公众号秘钥
- TemplateIdByProduct string //产品运行报告通知-模板ID
- WxYbAppId string // 研报小程序appid
- WxYbId string // 研报小程序微信原始ID
- WxYbAppSecret string // 研报小程序秘钥
- WxYbPlatform int //国能研报来源
- )
- // ES索引配置
- var (
- DATA_INDEX_NAME string //数据指标库索引
- CHART_INDEX_NAME string //研究图库索引
- EsReportIndexName string //研报ES索引
- EsEnglishReportIndexName string //英文研报ES索引
- MY_CHART_INDEX_NAME string //研究图库(MY ETA)索引
- EsSemanticAnalysisDocIndexName string //ES语义分析文档索引名
- SmartReportIndexName string //智能研报ES索引
- EsKnowledgeResourceIndexName string //ES知识库索引
- )
- var (
- XfHostUrl string // 科大讯飞--语音合成
- )
- // 对象存储客户端
- var (
- ObjectStorageClient string // 目前有oss minio,默认oss
- PptUpdateApi string //ppt 通过后端接口的方式上传
- )
- // 阿里云配置
- var (
- Bucketname string
- Endpoint string
- Imghost string
- UploadDir string
- Upload_Audio_Dir string
- AccessKeyId string
- AccessKeySecret string
- )
- // 阿里云oss前端上传用
- var (
- AliStsScheme string
- RegionId string
- RoleArn string
- RoleSessionName string
- RAMAccessKeyId string
- RAMAccessKeySecret string
- STSTokenCacheKey string
- )
- // 阿里云邮箱配置
- var (
- AliyunEmailAccountName string
- AliyunEmailAccessKeyId string
- AliyunEmailAccessKeySecret string
- AliyunEmailReplyAddress string
- AliyunEmailReplyAddressAlias string
- )
- // 腾讯云邮箱配置
- var (
- TencentSDKSecretId string // 腾讯云主账号SecretId
- TencentSDKSecretKey string // 腾讯云主账号SecretKey
- TencentEmailFromEmailAddress string // 腾讯云邮件发信地址
- TencentEmailTemplateID uint64 // 云邮件模板ID
- )
- // LibreOfficePath LibreOfficePath的地址
- var LibreOfficePath string
- // CrmEtaServerUrl CRM-ETA服务地址
- var (
- CrmEtaServerUrl string
- CrmEtaServerDes3Key string
- )
- // eta_forum_hub ETA社区桥接服务地址
- var (
- ETA_FORUM_HUB_URL string
- ETA_FORUM_HUB_NAME_EN string
- ETA_FORUM_HUB_MD5_KEY string
- )
- // BusinessCode 商家编码
- var BusinessCode string
- // 日志配置
- var (
- LogPath string //调用过程中的日志存放地址
- LogFile string
- LogDataPath string //调用过程中图表相关的日志存放地址
- LogDataFile string
- BinLogPath string //数据库相关的日志存放地址
- BinLogFile string
- ApiLogPath string //接口请求地址和接口返回值日志存放地址
- ApiLogFile string
- LogMaxDays int //日志最大保留天数
- )
- // MinIo配置
- var (
- MinIoBucketname string
- MinIoEndpoint string
- MinIoBackEndpoint string
- MinIoImghost string
- MinIoUploadDir string
- MinIoUpload_Audio_Dir string
- MinIoAccessKeyId string
- MinIoAccessKeySecret string
- MinIoUseSSL string
- MinIoPort string
- MinIoRegion string
- )
- // PythonUrlReport2Img 生成长图服务地址
- var PythonUrlReport2Img string
- // ETA-AI服务
- var EtaAiUrl string
- var (
- EtaAppid string
- EtaSecret string
- )
- // S3配置
- var (
- S3Endpoint string
- S3BackEndpoint string
- S3BucketName string
- S3UploadDir string
- S3AccessKeyId string
- S3AccessKeySecret string
- S3Host string
- S3Region string
- S3ForceStyle string
- S3EndpointPort string
- S3Protocol string
- S3DisableSSL string
- S3OpenAcl string
- )
- // chrome配置
- var (
- ChromePath string // chrome浏览器地址
- )
- var (
- ErrMsgConfigFile string
- )
- var (
- ViperConfig *viper.Viper
- )
- var (
- UseMongo bool // 是否使用mongo
- )
- func init() {
- tmpRunMode, err := web.AppConfig.String("run_mode")
- if err != nil {
- panic(any("配置文件读取run_mode错误 " + err.Error()))
- }
- RunMode = tmpRunMode
- if RunMode == "" {
- configPath := `/home/code/config/eta_gn/eta_api/conf/app.conf`
- fmt.Println("configPath:", configPath)
- err = web.LoadAppConfig("ini", configPath)
- if err != nil {
- fmt.Println("web.LoadAppConfig Err:" + err.Error())
- }
- tmpRunMode, err = web.AppConfig.String("run_mode")
- if err != nil {
- panic(any("配置文件读取run_mode错误 " + err.Error()))
- }
- RunMode = tmpRunMode
- }
- fmt.Println("RunMode:", RunMode)
- config, err := web.AppConfig.GetSection(RunMode)
- if err != nil {
- panic(any("配置文件读取错误 " + err.Error()))
- }
- beeLogger.Log.Info(RunMode + " 模式")
- MYSQL_URL = config["mysql_url"]
- MYSQL_URL_RDDP = config["mysql_url_rddp"]
- MYSQL_URL_EDB = config["mysql_url_edb"]
- MYSQL_URL_DATA = config["mysql_url_data"]
- MYSQL_URL_GL = config["mysql_url_gl"]
- MYSQL_LOG_URL = config["mysql_url_log"]
- // 用户主库
- MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
- // 用户主库
- MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
- //ETA-AI
- MYSQL_AI_URL = config["mysql_url_ai"]
- // mongodb数据库连接配置
- MgoUrlData = config["mgo_url_data"]
- REDIS_CACHE = config["beego_cache"]
- if len(REDIS_CACHE) <= 0 {
- panic(any("redis链接参数没有配置"))
- }
- //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
- //if Re != nil {
- // fmt.Println("redis链接异常:", Re)
- // panic(any(Re))
- //}
- // 初始化缓存
- redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
- if err != nil {
- fmt.Println("redis链接异常:", err)
- panic(any(Re))
- }
- Rc = redisClient
- // 项目中文名称
- appNameCn, err := web.AppConfig.String("app_name_cn")
- if err != nil {
- panic(any("配置文件读取app_name_cn错误 " + err.Error()))
- }
- APPNAME = appNameCn
- // 初始化内部服务配置
- // 接口返回加密KEY
- DesKey = config["des_key"]
- // 邮件提醒人员
- EmailSendToUsers = config["email_send_to_users"]
- // 聚合短信,国内AppKey
- JhGnAppKey = config["jh_gn_app_key"]
- JhGjAppKey = config["jh_gj_app_key"]
- // ppt 转图片服务地址
- Ppt2ImageUrl = config["ppt2_image_url"]
- // 静态文件目录
- STATIC_DIR = config["static_dir"]
- // 代理资源地址
- ResourceProxyUrl = config["resource_proxy_url"]
- RESOURCE_DIR = config["resource_dir"]
- if RESOURCE_DIR == "" {
- RESOURCE_DIR = "eta_gn/"
- }
- // 系统内部服务地址
- {
- // 公共指标库相关
- EDB_LIB_URL = config["edb_lib_url"]
- APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
- EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
- // 图表项目域名
- PublicChartHost = config["public_chart_host"]
- // 钢联化工服务地址
- MySteelPostUrl = config["mysteel_post_url"]
- // 发送微信模板消息地址
- SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
- // 发送微信模板消息地址
- SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
- // 语音分贝处理的地址
- HandleVideoDecibelUrl = config["handle_video_decibel_url"]
- // 国能open api的地址
- HongzeOpenApiHost = config["hongze_open_api_host"]
- // 英文研报分享的地址
- EnglishShareUrl = config["english_share_url"]
- // 策略报告地址
- EnPolicyReportUrl = config["en_policy_report_url"]
- // 谷歌翻译服务地址
- GoogleTranslateUrl = config["google_translate_url"]
- // 报警服务地址
- AlarmMsgUrl = config["alarm_msg_url"]
- // chatGPT服务地址
- ChatUrl = config["chat_url"]
- EtaBridgeUrl = config["eta_bridge_url"] // 桥接服务地址
- EtaBridgeAppNameEn = config["eta_bridge_app_name_en"] // 桥接服务英文名称-鉴权用
- EtaBridgeMd5Key = config["eta_bridge_md5_key"] // 桥接服务Md5密钥-鉴权用
- EtaBridgeDesKey = config["eta_bridge_des_key"] // 桥接服务Des密钥-解密数据用
- EtaBridgeLoginUrl = config["eta_bridge_login_url"] // eta桥接服务-登录接口地址
- EtaBridgeLogoutUrl = config["eta_bridge_logout_url"] // eta桥接服务-登出接口地址
- }
- //日志配置
- {
- LogPath = config["log_path"]
- LogFile = config["log_file"]
- LogDataPath = config["log_data_path"]
- LogDataFile = config["log_data_file"]
- BinLogPath = config["binlog_path"]
- BinLogFile = config["binlog_file"]
- ApiLogPath = config["apilog_path"]
- ApiLogFile = config["apilog_file"]
- logMaxDaysStr := config["log_max_day"]
- LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
- }
- // ES配置
- {
- ES_URL = config["es_url"]
- ES_USERNAME = config["es_username"]
- ES_PASSWORD = config["es_password"]
- }
- // 微信相关
- {
- WxAppId = config["wx_appid"]
- WxAppSecret = config["wx_app_secret"]
- WxId = config["wx_id"]
- //模板消息
- TemplateIdByProduct = config["template_id_by_product"]
- WxYbAppId = config["wx_yb_appid"] //国能研报小程序
- WxYbId = config["wx_yb_id"] // 研报小程序微信原始ID
- WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
- wxYbPlatformStr := config["wx_yb_platform"]
- if wxYbPlatformStr != `` {
- WxYbPlatform, err = strconv.Atoi(wxYbPlatformStr) //国能研报来源
- if err != nil {
- panic(any("配置文件读取wx_yb_platform错误 " + err.Error()))
- }
- }
- }
- // 对象存储客户端
- ObjectStorageClient = config["object_storage_client"]
- // ppt上传是否走后端
- PptUpdateApi = config["ppt_update_api"]
- // OSS相关
- {
- Endpoint = config["endpoint"]
- Bucketname = config["bucket_name"]
- Imghost = config["img_host"]
- UploadDir = config["upload_dir"]
- Upload_Audio_Dir = config["upload_audio_dir"]
- AccessKeyId = config["access_key_id"]
- AccessKeySecret = config["access_key_secret"]
- }
- // OSS相关(前端使用)
- {
- AliStsScheme = config["ali_sts_scheme"]
- RegionId = config["region_id"]
- RoleArn = config["role_arn"]
- RoleSessionName = config["role_session_name"]
- RAMAccessKeyId = config["ram_access_key_id"]
- RAMAccessKeySecret = config["ram_access_key_secret"]
- STSTokenCacheKey = config["sts_token_cache_key"]
- }
- // 阿里云邮箱配置
- {
- AliyunEmailAccountName = config["aliyun_email_account_name"]
- AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
- AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
- AliyunEmailReplyAddress = config["aliyun_email_reply_address"]
- AliyunEmailReplyAddressAlias = config["aliyun_email_reply_address_alias"]
- }
- // 腾讯云邮箱配置
- {
- TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
- TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
- TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
- tencentEmailTemplateIDtr := config["tencent_email_template_id"]
- if tencentEmailTemplateIDtr != `` {
- tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //国能研报来源
- if err != nil {
- panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
- }
- TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
- }
- }
- // 科大讯飞
- {
- //XfAPPID = config["xf_appid"]
- //XfAPIKey = config["xf_api_key"]
- //XfAPISecret = config["xf_api_secret"]
- XfHostUrl = config["xf_host_url"]
- //XfOrigin = config["xf_origin"]
- //XfVcn = config["xf_vcn"]
- }
- // ES 索引
- {
- DATA_INDEX_NAME = config["data_index_name"]
- CHART_INDEX_NAME = config["chart_index_name"]
- MY_CHART_INDEX_NAME = config["my_chart_index_name"]
- EsReportIndexName = config["es_report_index_name"]
- EsEnglishReportIndexName = config["es_english_report_index_name"]
- EsSemanticAnalysisDocIndexName = config["es_semantic_analysis_doc_index_name"]
- SmartReportIndexName = config["es_smart_report_index_name"]
- EsKnowledgeResourceIndexName = config["es_knowledge_resource_index_name"]
- }
- CrmEtaServerUrl = config["crm_eta_server_url"]
- CrmEtaServerDes3Key = config["crm_eta_server_des3_key"]
- LibreOfficePath = config["libre_office_path"]
- // eta_forum_hub ETA社区桥接服务地址
- {
- ETA_FORUM_HUB_URL = config["eta_forum_hub_url"]
- ETA_FORUM_HUB_NAME_EN = config["eta_forum_hub_name_en"]
- ETA_FORUM_HUB_MD5_KEY = config["eta_forum_hub_md5_key"]
- }
- // 商家编码
- BusinessCode = config["business_code"]
- // eta_mini_bridge 小程序桥接服务地址
- {
- ETAMiniBridgeUrl = config["eta_mini_bridge_url"]
- ETA_MINI_APPID = config["eta_mini_bridge_appid"] // 桥接服务-鉴权用
- ETA_MINI_APP_SECRET = config["eta_mini_bridge_secret"] // 桥接服务-鉴权用
- }
- // MinIo相关
- {
- MinIoEndpoint = config["minio_endpoint"]
- MinIoBackEndpoint = config["minio_back_endpoint"]
- MinIoBucketname = config["minio_bucket_name"]
- MinIoImghost = config["minio_img_host"]
- MinIoUploadDir = config["minio_upload_dir"]
- MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
- MinIoAccessKeyId = config["minio_access_key_id"]
- MinIoAccessKeySecret = config["minio_access_key_secret"]
- MinIoUseSSL = config["minio_use_ssl"]
- MinIoPort = config["minio_port"]
- MinIoRegion = config["minio_region"]
- }
- // S3-OSS相关
- {
- S3Endpoint = config["s3_endpoint"]
- S3BackEndpoint = config["s3_back_endpoint"]
- S3BucketName = config["s3_bucket_name"]
- S3Host = config["s3_host"]
- S3AccessKeyId = config["s3_access_key_id"]
- S3AccessKeySecret = config["s3_access_key_secret"]
- S3UploadDir = config["s3_upload_dir"]
- S3Region = config["s3_region"]
- S3ForceStyle = config["s3_force_style"]
- S3EndpointPort = config["s3_endpoint_port"]
- S3Protocol = config["s3_protocol"]
- S3DisableSSL = config["s3_disable_ssl"]
- S3OpenAcl = config["s3_open_acl"]
- }
- // 生成长图服务地址
- PythonUrlReport2Img = config["python_url_report2img"]
- EtaAiUrl = config["eta_ai_url"]
- EtaAppid = config["eta_appid"]
- EtaSecret = config["eta_secret"]
- // chrome配置
- ChromePath = config["chrome_path"]
- // 初始化ES
- initEs()
- ErrMsgConfigFile = config["err_msg_config_file"]
- if ErrMsgConfigFile != "" {
- viper.SetConfigFile(ErrMsgConfigFile)
- err = viper.ReadInConfig()
- if err != nil {
- if _, ok := err.(viper.ConfigFileNotFoundError); ok {
- fmt.Println(errors.New("config file not found"))
- panic(any("config file not found"))
- } else {
- fmt.Println(errors.New("config file was found but another error was produced err:" + err.Error()))
- panic(any("config file was found but another error was produced err:" + err.Error()))
- }
- return
- }
- ViperConfig = viper.GetViper()
- }
- }
|