123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package utils
- import (
- "fmt"
- beeLogger "github.com/beego/bee/v2/logger"
- "github.com/beego/beego/v2/server/web"
- )
- // 数据库配置
- var (
- RunMode string // 运行模式
- MYSQL_URL_MASTER string // 数据库地址
- MYSQL_URL_RDDP string // 数据库地址
- REDIS_CACHE string //缓存地址
- Rc RedisClient //redis缓存
- )
- var ObjectStorageClient string // 目前有oss minio,默认oss
- // 阿里云配置
- var (
- Bucketname string
- Endpoint string
- Imghost string
- UploadDir string
- AccessKeyId string
- AccessKeySecret string
- )
- // MinIo配置
- var (
- MinIoBucketname string
- MinIoEndpoint string
- MinIoBackEndpoint string
- MinIoPdfhost string
- MinIoUploadDir string
- MinIoAccessKeyId string
- MinIoAccessKeySecret string
- MinIoUseSSL string
- MinIoPort string
- MinIoRegion string
- )
- // 阿里云oss前端上传用
- var (
- AliStsScheme string
- RegionId string
- RoleArn string
- RoleSessionName string
- RAMAccessKeyId string
- RAMAccessKeySecret string
- STSTokenCacheKey string
- )
- // 基础配置
- var (
- STATIC_DIR string
- RESOURCE_DIR string
- UPLOAD_PDF_SIZE string // 单位MB
- )
- // ES配置
- var (
- ES_URL string // ES服务器地址
- ES_USERNAME string // ES账号
- ES_PASSWORD string // ES密码
- )
- // ES索引配置
- var (
- MINI_REPORT_INDEX_NAME string // 小程序的pdf报告索引
- )
- var (
- LogPath string //调用过程中的日志存放地址
- LogFile string
- ApiLogPath string // 接口请求地址和接口返回值日志存放地址
- ApiLogFile string
- BinLogPath string // 数据库相关的日志存放地址
- BinLogFile string
- LogMaxDays int // 日志最大保留天数
- )
- var DesKey string // 接口返回加密KEY
- func init() {
- tmpRunMode, err := web.AppConfig.String("run_mode")
- if err != nil {
- panic(any("配置文件读取run_mode错误 " + err.Error()))
- }
- RunMode = tmpRunMode
- fmt.Println("RunMode:", RunMode)
- if RunMode == "" {
- configPath := `/home/code/config/eta_mini_crm/conf/app.conf`
- fmt.Println("configPath:", configPath)
- err = web.LoadAppConfig("ini", configPath)
- if err != nil {
- fmt.Println("web.LoadAppConfig Err:" + err.Error())
- }
- tmpRunMode, _ := web.AppConfig.String("run_mode")
- RunMode = tmpRunMode
- }
- config, err := web.AppConfig.GetSection(RunMode)
- if err != nil {
- panic(any("配置文件读取错误 " + err.Error()))
- }
- beeLogger.Log.Info(RunMode + " 模式")
- MYSQL_URL_RDDP = config["mysql_url_rddp"]
- MYSQL_URL_MASTER = config["mysql_url_master"]
- REDIS_CACHE = config["beego_cache"]
- if len(REDIS_CACHE) <= 0 {
- panic(any("redis链接参数没有配置"))
- }
- // 接口返回加密KEY
- DesKey = config["des_key"]
- // 对象存储客户端
- ObjectStorageClient = config["object_storage_client"]
- if ObjectStorageClient == "" {
- ObjectStorageClient = "oss"
- }
- // OSS相关
- {
- Endpoint = config["endpoint"]
- Bucketname = config["bucket_name"]
- Imghost = config["img_host"]
- UploadDir = config["upload_dir"]
- AccessKeyId = config["access_key_id"]
- AccessKeySecret = config["access_key_secret"]
- }
- // MinIo相关
- {
- MinIoEndpoint = config["minio_endpoint"]
- MinIoBackEndpoint = config["minio_back_endpoint"]
- MinIoBucketname = config["minio_bucket_name"]
- MinIoPdfhost = config["minio_pdf_host"]
- MinIoUploadDir = config["minio_upload_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"]
- }
- // 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"]
- }
- // ES配置
- {
- ES_URL = config["es_url"]
- ES_USERNAME = config["es_username"]
- ES_PASSWORD = config["es_password"]
- }
- // ES 索引
- {
- MINI_REPORT_INDEX_NAME = config["mini_report_index_name"]
- }
- // 初始化ES
- initEs()
- // 静态文件目录
- STATIC_DIR = config["static_dir"]
- if STATIC_DIR == "" {
- STATIC_DIR = "./static"
- }
- RESOURCE_DIR = config["resource_dir"]
- if RESOURCE_DIR == "" {
- RESOURCE_DIR = "dongwu/"
- }
- UPLOAD_PDF_SIZE = config["upload_pdf_size"]
- if UPLOAD_PDF_SIZE == "" {
- UPLOAD_PDF_SIZE = "15"
- }
- // 初始化缓存
- redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
- if err != nil {
- fmt.Println("redis链接异常:", err)
- panic(any("redis链接参数没有配置"))
- }
- Rc = redisClient
- }
|