config.go 2.2 KB
package config

import (
	"fmt"

	"github.com/astaxie/beego"
)

//MyConfig 自定义配置选项
type MyConfig struct {
	ConfigName       string //配置名称
	SqlConn          string //数据库连接
	RedisAddPort     string //
	RedisAuth        string
	RedisDB          int
	LogOutput        string
	LogFilename      string
	LogLevel         string
	UcenterCheckAlt  string
	UcenterBaseUrl   string
	UcenterSecret    string
	UcenterAppKey    string
	FileSavePath     string
	FileHost         string
	FileHostPath     string
	BusinessAdminUrl string
}

//MConfig
var MConfig *MyConfig

func RestMyConfig() *MyConfig {
	fmt.Println("初始化config")
	mysqlHost := beego.AppConfig.String("mysql_host")
	mysqlPort := beego.AppConfig.String("mysql_port")
	mysqlUser := beego.AppConfig.String("mysql_user")
	mysqlPassword := beego.AppConfig.String("mysql_password")
	mysqlDBname := beego.AppConfig.String("mysql_db_name")
	sqlconn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
		mysqlUser, mysqlPassword, mysqlHost, mysqlPort, mysqlDBname)
	sqlconn = sqlconn + "?charset=utf8&loc=Asia%2FShanghai"
	MConfig = &MyConfig{
		ConfigName:       beego.AppConfig.String("config_name"),
		SqlConn:          sqlconn,
		RedisAddPort:     fmt.Sprintf("%s:%s", beego.AppConfig.String("redis_add"), beego.AppConfig.String("redis_add_port")),
		RedisAuth:        beego.AppConfig.DefaultString("redis_auth", ""),
		RedisDB:          beego.AppConfig.DefaultInt("redis_db", 0),
		LogOutput:        beego.AppConfig.DefaultString("log_output", "console"),
		LogFilename:      beego.AppConfig.DefaultString("log_filename", "./log/ability.log"),
		LogLevel:         beego.AppConfig.DefaultString("log_Level", "debug"),
		UcenterCheckAlt:  beego.AppConfig.String("ucenter_check_alt"),
		UcenterBaseUrl:   beego.AppConfig.String("ucenter_base_url"),
		UcenterSecret:    beego.AppConfig.String("ucenter_secret"),
		UcenterAppKey:    beego.AppConfig.String("ucenter_app_key"),
		FileSavePath:     beego.AppConfig.String("file_save_path"),
		FileHost:         beego.AppConfig.String("file_host"),
		FileHostPath:     beego.AppConfig.String("file_host_path"),
		BusinessAdminUrl: beego.AppConfig.String("business_admin_url"),
	}
	return MConfig
}