add migration from versions 0.3.3, 0.3.4, 0.3.5 (#3)

This commit is contained in:
Tiger Wang (王豫)
2022-08-12 00:07:50 -04:00
committed by GitHub
parent 52d38428b6
commit 0b66fd838f
20 changed files with 358 additions and 24 deletions
+1 -11
View File
@@ -1,15 +1,5 @@
/*
* @Author: LinkLeong link@icewhale.com
* @Date: 2021-09-30 18:18:14
* @LastEditors: LinkLeong
* @LastEditTime: 2022-06-21 11:09:30
* @FilePath: /CasaOS/pkg/config/config.go
* @Description:
* @Website: https://www.casaos.io
* Copyright (c) 2022 by icewhale, All Rights Reserved.
*/
package config
const (
USERCONFIGURL = "/etc/casaos/casaos.conf"
UserServiceConfigFilePath = "/etc/casaos/user-service.conf"
)
+25 -4
View File
@@ -26,15 +26,14 @@ var AppInfo = &model.APPModel{
var Cfg *ini.File
func InitSetup(config string) {
var configDir = USERCONFIGURL
configFilePath := UserServiceConfigFilePath
if len(config) > 0 {
configDir = config
configFilePath = config
}
var err error
Cfg, err = ini.Load(configDir)
Cfg, err = ini.Load(configFilePath)
if err != nil {
fmt.Printf("Fail to read file: %v", err)
os.Exit(1)
@@ -44,9 +43,31 @@ func InitSetup(config string) {
mapTo("app", AppInfo)
}
func SaveSetup(config string) {
reflectFrom("common", CommonInfo)
reflectFrom("app", AppInfo)
configFilePath := UserServiceConfigFilePath
if len(config) > 0 {
configFilePath = config
}
if err := Cfg.SaveTo(configFilePath); err != nil {
fmt.Printf("Fail to save file: %v", err)
os.Exit(1)
}
}
func mapTo(section string, v interface{}) {
err := Cfg.Section(section).MapTo(v)
if err != nil {
log.Fatalf("Cfg.MapTo %s err: %v", section, err)
}
}
func reflectFrom(section string, v interface{}) {
err := Cfg.Section(section).ReflectFrom(v)
if err != nil {
log.Fatalf("Cfg.ReflectFrom %s err: %v", section, err)
}
}