添加默认配置
This commit is contained in:
parent
3e8a2938c0
commit
db73c16fe3
|
|
@ -86,6 +86,27 @@ type ConfigStruct struct {
|
||||||
|
|
||||||
// 读取配置文件
|
// 读取配置文件
|
||||||
func ReadConfig(path string) error {
|
func ReadConfig(path string) error {
|
||||||
|
//查看配置文件是否存在,不存在则创建
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Config file not found!")
|
||||||
|
//创建默认配置
|
||||||
|
DefaultConfig()
|
||||||
|
//写入json文件
|
||||||
|
file, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error creating config file")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
encoder := json.NewEncoder(file)
|
||||||
|
err = encoder.Encode(&Config)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error encoding config")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
//读json文件
|
//读json文件
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -105,3 +126,26 @@ func ReadConfig(path string) error {
|
||||||
SigningKey = []byte(Config.TOKEN_SECRET)
|
SigningKey = []byte(Config.TOKEN_SECRET)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 默认配置
|
||||||
|
func DefaultConfig() {
|
||||||
|
Config.DB = 2
|
||||||
|
Config.MYSQL_DSN = MYSQL_DSN
|
||||||
|
Config.PG_DSN = ""
|
||||||
|
Config.REDIS_ADDR = REDIS_ADDR
|
||||||
|
Config.TOKEN_USE_REDIS = false
|
||||||
|
Config.REDIS_User_PW = false
|
||||||
|
Config.REDIS_PASSWORD = REDIS_PASSWORD
|
||||||
|
Config.REDIS_DB = REIDS_DB
|
||||||
|
Config.TOKEN_SECRET = TOKEN_SECRET
|
||||||
|
Config.CID_BASE_DIR = CID_BASE_DIR
|
||||||
|
Config.FILE_BASE_DIR = FILE_BASE_DIR
|
||||||
|
Config.MONITOR = false
|
||||||
|
Config.SERVER_SQL_LOG = false
|
||||||
|
Config.SERVER_PORT = "8083"
|
||||||
|
Config.LOG_SAVE_DAYS = 7
|
||||||
|
Config.SERVER_USER_TYPE = "master"
|
||||||
|
Config.MASTER_SERVER_DOMAIN = ""
|
||||||
|
Config.USER_SYNC_TIME = 86400
|
||||||
|
Config.SERVER_NAME = "default"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue