mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-10-06 19:59:42 +07:00
add migration from versions 0.3.3, 0.3.4, 0.3.5 (#3)
This commit is contained in:
+1
-11
@@ -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
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user