From 9c1fef030962c23708b61cf6704ac42f11e83009 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Fri, 10 Feb 2023 14:22:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/viper/viper.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index 7a5b241ae..7e7fee8d4 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -3,6 +3,8 @@ package viper import ( "bytes" "fmt" + "github.com/1Panel-dev/1Panel/backend/utils/files" + "path" "strings" "github.com/1Panel-dev/1Panel/backend/utils/cmd" @@ -15,19 +17,29 @@ import ( ) func Init() { - stdout, err := cmd.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2") - if err != nil { - panic(err) - } - baseDir := strings.ReplaceAll(stdout, "\n", "") - if len(baseDir) == 0 { - panic("error `BASE_DIR` find in /usr/bin/1pctl") - } + baseDir := "/opt" + fileOp := files.NewFileOp() v := viper.NewWithOptions() v.SetConfigType("yaml") - reader := bytes.NewReader(conf.AppYaml) - if err := v.ReadConfig(reader); err != nil { - panic(fmt.Errorf("Fatal error config file: %s \n", err)) + if fileOp.Stat("/opt/1panel/conf/app.yaml") { + v.SetConfigName("app") + v.AddConfigPath(path.Join("/opt/1pane/conf")) + if err := v.ReadInConfig(); err != nil { + panic(fmt.Errorf("Fatal error config file: %s \n", err)) + } + } else { + stdout, err := cmd.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2") + if err != nil { + panic(err) + } + baseDir = strings.ReplaceAll(stdout, "\n", "") + if len(baseDir) == 0 { + panic("error `BASE_DIR` find in /usr/bin/1pctl") + } + reader := bytes.NewReader(conf.AppYaml) + if err := v.ReadConfig(reader); err != nil { + panic(fmt.Errorf("Fatal error config file: %s \n", err)) + } } v.OnConfigChange(func(e fsnotify.Event) { if err := v.Unmarshal(&global.CONF); err != nil {