123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package utils
- import (
- "fmt"
- "github.com/beego/beego/v2/server/web"
- "strconv"
- )
- var (
- RunMode string //运行模式
- MYSQL_URL string //数据库连接
- MYSQL_URL_ETA string
- )
- // 日志配置
- 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
- Html2ImgServerUrl string // html转图片服务地址
- EtaReportAppNameEn string // 内部调用该服务的英文名
- EtaReportKey string // 内部调用该服务的鉴权Key
- )
- 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_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"]
- //日志配置
- {
- 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"]
- // html转图片服务地址
- Html2ImgServerUrl = config["html2img_server_url"]
- // 内部调用项目英文名
- EtaReportAppNameEn = config["eta_report_app_name_en"]
- // 内部调用鉴权Key
- EtaReportKey = config["eta_report_key"]
- }
- }
|