From a4a25f5304613a94b67d1c46f4e7c3a40d4fc6b4 Mon Sep 17 00:00:00 2001 From: copy rogers <40619032+rogerogers@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:11:31 +0800 Subject: [PATCH] Revert "fix: add absolute path for config (#84)" (#96) This reverts commit 97b4535f6fa2d113d59f2e7c09ad80787a2a1171. --- tpl/hertz/server/standard/layout.yaml | 32 ++++-------------------- tpl/kitex/server/standard/conf_tpl.yaml | 33 +++---------------------- 2 files changed, 9 insertions(+), 56 deletions(-) diff --git a/tpl/hertz/server/standard/layout.yaml b/tpl/hertz/server/standard/layout.yaml index 367d6f78..5a39e36b 100644 --- a/tpl/hertz/server/standard/layout.yaml +++ b/tpl/hertz/server/standard/layout.yaml @@ -115,14 +115,11 @@ layouts: package conf import ( - "bytes" "io/ioutil" "os" - "os/exec" "path/filepath" "sync" - "github.com/bytedance/sonic" "github.com/cloudwego/hertz/pkg/common/hlog" "github.com/kr/pretty" "gopkg.in/validator.v2" @@ -146,6 +143,7 @@ layouts: DSN string `yaml:"dsn"` } + type Redis struct { Address string `yaml:"address"` Password string `yaml:"password"` @@ -164,10 +162,6 @@ layouts: LogMaxBackups int `yaml:"log_max_backups"` LogMaxAge int `yaml:"log_max_age"` } - - type BindMainDir struct { - Dir string `json:"Dir"` - } // GetConf gets configuration instance func GetConf() *Config { @@ -176,7 +170,8 @@ layouts: } func initConf() { - confFileRelPath := getConfAbsPath() + prefix := "conf" + confFileRelPath := filepath.Join(prefix, filepath.Join(GetEnv(), "conf.yaml")) content, err := ioutil.ReadFile(confFileRelPath) if err != nil { panic(err) @@ -197,26 +192,7 @@ layouts: pretty.Printf("%+v\n", conf) } - - func getConfAbsPath() string { - cmd := exec.Command("go", "list", "-m", "-json") - - var out bytes.Buffer - cmd.Stdout = &out - cmd.Stderr = &out - if err := cmd.Run(); err != nil { - panic(err) - } - - bindDir := &BindMainDir{} - if err := sonic.Unmarshal(out.Bytes(), bindDir); err != nil { - panic(err) - } - prefix := "conf" - return filepath.Join(bindDir.Dir, prefix, filepath.Join(GetEnv(), "conf.yaml")) - } - func GetEnv() string { e := os.Getenv("GO_ENV") if len(e) == 0 { @@ -247,6 +223,7 @@ layouts: } } + - path: conf/dev/conf.yaml delims: - "" @@ -322,6 +299,7 @@ layouts: password: "" db: 0 + - path: biz/dal/init.go delims: - "" diff --git a/tpl/kitex/server/standard/conf_tpl.yaml b/tpl/kitex/server/standard/conf_tpl.yaml index 67231a9c..38de9dfe 100644 --- a/tpl/kitex/server/standard/conf_tpl.yaml +++ b/tpl/kitex/server/standard/conf_tpl.yaml @@ -5,14 +5,11 @@ body: |- package conf import ( - "bytes" "io/ioutil" "os" - "os/exec" "path/filepath" "sync" - "github.com/bytedance/sonic" "github.com/cloudwego/kitex/pkg/klog" "github.com/kr/pretty" "gopkg.in/validator.v2" @@ -35,7 +32,7 @@ body: |- type MySQL struct { DSN string `yaml:"dsn"` } - + type Redis struct { Address string `yaml:"address"` Username string `yaml:"username"` @@ -61,10 +58,6 @@ body: |- Username string `yaml:"username"` Password string `yaml:"password"` } - - type BindMainDir struct { - Dir string `json:"Dir"` - } // GetConf gets configuration instance func GetConf() *Config { @@ -73,7 +66,8 @@ body: |- } func initConf() { - confFileRelPath := getConfAbsPath() + prefix := "conf" + confFileRelPath := filepath.Join(prefix, filepath.Join(GetEnv(), "conf.yaml")) content, err := ioutil.ReadFile(confFileRelPath) if err != nil { panic(err) @@ -91,25 +85,6 @@ body: |- conf.Env = GetEnv() pretty.Printf("%+v\n", conf) } - - func getConfAbsPath() string { - cmd := exec.Command("go", "list", "-m", "-json") - - var out bytes.Buffer - cmd.Stdout = &out - cmd.Stderr = &out - if err := cmd.Run(); err != nil { - panic(err) - } - - bindDir := &BindMainDir{} - if err := sonic.Unmarshal(out.Bytes(), bindDir); err != nil { - panic(err) - } - - prefix := "conf" - return filepath.Join(bindDir.Dir, prefix, filepath.Join(GetEnv(), "conf.yaml")) - } func GetEnv() string { e := os.Getenv("GO_ENV") @@ -118,7 +93,7 @@ body: |- } return e } - + func LogLevel() klog.Level { level := GetConf().Kitex.LogLevel switch level {