package controllers

import (
	"spaceofcheng/services/utils"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/config"
)

// 配置文件列表
const (
	AliYunConf = "aliyun"
	WeChatConf = "wechat"
	SMSConf    = "sms"
)

func (c *BaseController) initConfig() {
	c.RunMode = beego.AppConfig.String("runmode")

	if c.Configer == nil {
		c.Configer = make(map[string]config.Configer)
	}

	// 阿里云
	aliConf := c.getConfig("conf/aliyun.conf")
	if aliConf != nil {
		c.Configer[AliYunConf] = aliConf
	}

	// 短信
	smsConf := c.getConfig("conf/sms.conf")
	if smsConf != nil {
		c.Configer[SMSConf] = smsConf
	}
	utils.ResetSMSEngine(smsConf)
}

func (c *BaseController) getConfig(confPath string) config.Configer {
	aliConf, err := config.NewConfig("ini", confPath)
	if err != nil {
		utils.LogError("读取配置文件失败: " + err.Error())
		return nil
	}

	return aliConf
}
