修改配置写入
This commit is contained in:
parent
b1bb1cb734
commit
44b74e468b
|
|
@ -126,25 +126,7 @@ func ReadConfig(path string) error {
|
||||||
fmt.Println("Config file not found!")
|
fmt.Println("Config file not found!")
|
||||||
//创建默认配置
|
//创建默认配置
|
||||||
DefaultConfig()
|
DefaultConfig()
|
||||||
//写入json文件
|
WriteConfigToFile()
|
||||||
file, err := os.Create(path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error creating config file")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
encoder := json.NewEncoder(file)
|
|
||||||
|
|
||||||
configData, err2 := json.MarshalIndent(Config, "", " ")
|
|
||||||
if err2 != nil {
|
|
||||||
log.Println("WriteConfigToFile json marshal error:", err)
|
|
||||||
return err2
|
|
||||||
}
|
|
||||||
err = encoder.Encode(string(configData))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error encoding config")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//读json文件
|
//读json文件
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue