123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- package utils
- import (
- "fmt"
- "strconv"
- "github.com/beego/beego/v2/server/web"
- )
- var (
- RunMode string //运行模式
- MYSQL_URL string //数据库连接
- MYSQL_URL_ETA string
- MYSQL_WEEKLY_URL string //CRM主库
- REDIS_CACHE string //缓存地址
- //Rc *cache.Cache //redis缓存
- Re error //redis错误
- Rc RedisClient //redis缓存
- )
- // 日志配置
- var (
- LogPath string //调用过程中的日志存放地址
- LogFile string
- BinLogPath string //数据库相关的日志存放地址
- BinLogFile string
- ApiLogPath string //接口请求地址和接口返回值日志存放地址
- ApiLogFile string
- LogMaxDays int //日志最大保留天数
- )
- // 系统配置
- var (
- DesKey string // 加密key
- EmailSendToUsers string // 邮件提醒人员
- BusinessCode string // 商户号
- )
- // 公共api内部服务调用
- var (
- // EtaPubUrl 模板消息推送
- EtaPubUrl string
- // EtaPubAuthorization 模板推送秘钥
- EtaPubAuthorization string
- // AlarmMsgUrl 报警服务地址
- AlarmMsgUrl string
- Report2ImgServerUrl string // 报告详情转图片服务地址
- // ChartLibUrl 图库项目url
- ChartLibUrl string
- )
- // 对象存储客户端
- var (
- ObjectStorageClient string // 目前有oss minio,默认oss
- ResourceProxyUrl string // 代理资源地址
- )
- var (
- StaticDir string //静态文件目录
- )
- // 阿里云配置
- var (
- Bucketname string
- Endpoint string
- Imghost string
- UploadDir string
- UploadFileDir string
- Upload_Audio_Dir string
- AccessKeyId string
- AccessKeySecret string
- )
- // MinIo配置
- var (
- MinIoBucketname string
- MinIoEndpoint string
- MinIoImghost string
- MinIoUploadDir string
- MinIoUpload_Audio_Dir string
- MinIoAccessKeyId string
- MinIoAccessKeySecret string
- MinIoUseSSL string
- MinIoPort string
- MinIoRegion string
- )
- // S3配置
- var (
- S3Endpoint string
- S3BucketName string
- S3UploadDir string
- S3AccessKeyId string
- S3AccessKeySecret string
- S3Host string
- S3Region string
- S3ForceStyle string
- S3EndpointPort string
- S3Protocol string
- S3DisableSSL string
- S3OpenAcl string
- )
- // ES配置
- var (
- ES_URL string // ES服务器地址
- ES_USERNAME string // ES账号
- ES_PASSWORD string // ES密码
- )
- var (
- EsKnowledgeResourceIndexName string //ES知识资源库索引
- )
- var (
- AppId string
- Secret string
- )
- func init() {
- tmpRunMode, err := web.AppConfig.String("run_mode")
- if err != nil {
- panic("配置文件读取run_mode错误 " + err.Error())
- }
- RunMode = tmpRunMode
- if RunMode == "" {
- localIp, err := GetLocalIP()
- fmt.Println("localIp:", localIp)
- if localIp == "10.0.0.123" {
- RunMode = "debug"
- } else {
- RunMode = "release"
- }
- fmt.Println("RunMode:", RunMode)
- configPath := `/home/code/config/eta_gn/eta_report/conf/app.conf`
- fmt.Println("configPath:", configPath)
- err = web.LoadAppConfig("ini", configPath)
- if err != nil {
- fmt.Println("web.LoadAppConfig Err:" + err.Error())
- }
- }
- config, err := web.AppConfig.GetSection(RunMode)
- if err != nil {
- panic("配置文件读取错误 " + err.Error())
- }
- fmt.Println(RunMode + " 模式")
- MYSQL_URL = config["mysql_url"]
- MYSQL_URL_ETA = config["mysql_url_eta"]
- MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
- REDIS_CACHE = config["beego_cache"]
- if len(REDIS_CACHE) <= 0 {
- panic(any("redis链接参数没有配置"))
- }
- //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
- //if Re != nil {
- // fmt.Println(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
- //日志配置
- {
- LogPath = config["log_path"]
- LogFile = config["log_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)
- }
- // 系统配置
- {
- // 接口返回加密KEY
- DesKey = config["des_key"]
- // 邮件提醒人员
- EmailSendToUsers = config["email_send_to_users"]
- // 商户号
- BusinessCode = config["business_code"]
- }
- // 系统内部服务地址
- {
- // 发送微信模板消息地址
- EtaPubUrl = config["eta_pub_url"]
- // 发送微信模板消息地址
- EtaPubAuthorization = config["eta_pub_authorization"]
- // 报警服务地址
- AlarmMsgUrl = config["alarm_msg_url"]
- // 报告详情转图片服务地址
- Report2ImgServerUrl = config["report2img_server_url"]
- // 图表项目域名
- ChartLibUrl = config["chart_lib_url"]
- }
- // 对象存储客户端
- ObjectStorageClient = config["object_storage_client"]
- // 代理资源地址
- ResourceProxyUrl = config["resource_proxy_url"]
- // 静态资源目录
- StaticDir = config["static_dir"]
- // OSS相关
- {
- Endpoint = config["endpoint"]
- Bucketname = config["bucket_name"]
- Imghost = config["img_host"]
- UploadDir = config["upload_dir"]
- UploadFileDir = config["upload_file_dir"]
- Upload_Audio_Dir = config["upload_audio_dir"]
- AccessKeyId = config["access_key_id"]
- AccessKeySecret = config["access_key_secret"]
- }
- // MinIo相关
- {
- MinIoEndpoint = config["minio_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"]
- 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"]
- }
- // ES配置
- {
- ES_URL = config["es_url"]
- ES_USERNAME = config["es_username"]
- ES_PASSWORD = config["es_password"]
- }
- {
- // ES知识资源库索引
- EsKnowledgeResourceIndexName = config["es_knowledge_resource_index_name"]
- }
- AppId = config["appid"]
- Secret = config["secret"]
- initEs()
- }
|