123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package utils
- import (
- "fmt"
- "strconv"
- beeLogger "github.com/beego/bee/v2/logger"
- "github.com/beego/beego/v2/server/web"
- )
- var (
- RunMode string //运行模式
- MYSQL_URL string //数据库连接
- MYSQL_URL_DATA string
- )
- // 日志配置
- var (
- LogPath string //调用过程中的日志存放地址
- LogFile string
- BinLogPath string //数据库相关的日志存放地址
- BinLogFile string
- ApiLogPath string //接口请求地址和接口返回值日志存放地址
- ApiLogFile string
- LogMaxDays int //日志最大保留天数
- )
- var BusinessCode string //商户号
- // 卓创资讯
- var (
- SCI99_COOKIE_PATH string
- IS_INIT_SCI99 string
- )
- // 粮油商务网
- var (
- LY_USERNAME string
- LY_PASSWORD string
- LY_JSON_PATH string
- LY_OPEN string
- )
- var (
- EDB_LIB_URL string
- APP_EDB_LIB_NAME_EN string
- EDB_LIB_Md5_KEY string
- )
- var (
- OLD_EXCEL_PATH_JR 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"
- }
- configPath := `/home/code/config/eta_crawler/conf/app.conf`
- 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())
- }
- beeLogger.Log.Info(RunMode + " 模式")
- // 商家编码
- BusinessCode = config["business_code"]
- if BusinessCode == BusinessCodeRelease {
- MYSQL_URL = config["mysql_url"]
- MYSQL_URL_DATA = config["mysql_url_data"]
- }
- if BusinessCode == BusinessCodeFuBang {
- SCI99_COOKIE_PATH = config["sci99_cookie_path"]
- IS_INIT_SCI99 = config["is_init_sci99"]
- 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"]
- }
- if BusinessCode == BusinessCodeJinRui {
- APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
- EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
- EDB_LIB_URL = config["edb_lib_url"]
- OLD_EXCEL_PATH_JR = config["old_excel_path_jr"]
- }
- if RunMode == "release" {
- } else {
- }
- //日志配置
- {
- 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)
- }
- {
- LY_USERNAME = config["ly_username"]
- LY_PASSWORD = config["ly_password"]
- LY_JSON_PATH = config["ly_json_path"]
- LY_OPEN = config["ly_open"]
- }
- }
|