mirror of https://github.com/1Panel-dev/1Panel
feat: 修改配置文件读取逻辑
parent
5d14ea1da0
commit
b804f4ae46
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -18,18 +19,28 @@ import (
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
baseDir := "/opt"
|
baseDir := "/opt"
|
||||||
mode := "local"
|
mode := "dev"
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
v := viper.NewWithOptions()
|
v := viper.NewWithOptions()
|
||||||
v.SetConfigType("yaml")
|
v.SetConfigType("yaml")
|
||||||
if fileOp.Stat("/opt/1panel/conf/app.yaml") {
|
|
||||||
|
config := configs.ServerConfig{}
|
||||||
|
if err := yaml.Unmarshal(conf.AppYaml, &config); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if config.System.Mode != "" {
|
||||||
|
mode = config.System.Mode
|
||||||
|
}
|
||||||
|
if mode != "release" {
|
||||||
|
if !fileOp.Stat("/opt/1panel/conf/app.yaml") {
|
||||||
|
panic("conf file is not exist")
|
||||||
|
}
|
||||||
v.SetConfigName("app")
|
v.SetConfigName("app")
|
||||||
v.AddConfigPath(path.Join("/opt/1panel/conf"))
|
v.AddConfigPath(path.Join("/opt/1panel/conf"))
|
||||||
if err := v.ReadInConfig(); err != nil {
|
if err := v.ReadInConfig(); err != nil {
|
||||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mode = "release"
|
|
||||||
stdout, err := cmd.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2")
|
stdout, err := cmd.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -52,7 +63,7 @@ func Init() {
|
||||||
if err := v.Unmarshal(&serverConfig); err != nil {
|
if err := v.Unmarshal(&serverConfig); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if mode == "local" && serverConfig.System.BaseDir != "" {
|
if mode != "release" && serverConfig.System.BaseDir != "" {
|
||||||
baseDir = serverConfig.System.BaseDir
|
baseDir = serverConfig.System.BaseDir
|
||||||
}
|
}
|
||||||
global.CONF = serverConfig
|
global.CONF = serverConfig
|
||||||
|
|
|
@ -3,6 +3,7 @@ system:
|
||||||
app_repo_owner: 1Panel-dev
|
app_repo_owner: 1Panel-dev
|
||||||
app_repo_name: appstore
|
app_repo_name: appstore
|
||||||
base_dir: /opt
|
base_dir: /opt
|
||||||
|
mode: dev
|
||||||
|
|
||||||
log:
|
log:
|
||||||
level: debug
|
level: debug
|
||||||
|
|
Loading…
Reference in New Issue