From 1a349a4b2a5d31150a7b74c90e1ca04ccfd5a0b7 Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:22:22 +0800 Subject: [PATCH] fix: fix the zk don't start problem (#328) * feat: add some api about admin * feat: add some api about admin * fix: del the unuse method * fix: Optimized code * fix: fix the userID * fix: del the config code getting from zk * fix: fix the initRedis * fix: add the get Evn method in Config * fix: fix the config.yaml.template * fix: fix the env config * feat: add some conponent env * fix: fix the openIMURL * fix: find the zk don't connect error * fix: find the zk error * fix: test the jz error * fix: delt the log * fix: fix the component error * fix: fix the error of get env location * fix: fix the error * fix: fix the zk start error * fix: fix the Config * fix: testing * fix: fix the config.Env error * fix: fix the componentCheck * fix: fix the config * fix: find the error * fix: del the flag * fix: fix the error --- pkg/common/config/parse.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index c44f680ea..143c2f26d 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -79,6 +79,9 @@ func InitConfig(configFile string) error { if err := yaml.NewDecoder(bytes.NewReader(data)).Decode(&Config); err != nil { return fmt.Errorf("parse loacl openIMConfig file error: %w", err) } + if err != nil { + return utils.Wrap(err, configFile) + } if err := configGetEnv(); err != nil { return fmt.Errorf("get env error:%w", err) @@ -86,10 +89,6 @@ func InitConfig(configFile string) error { configData, err := yaml.Marshal(&Config) fmt.Printf("debug: %s\nconfig:\n%s\n", time.Now(), string(configData)) - if err != nil { - return utils.Wrap(err, configFile) - } - fmt.Printf("%s\nconfig:\n%s\n", time.Now(), string(configData)) return nil } @@ -226,7 +225,6 @@ func configGetEnv() error { Config.Zookeeper.Schema = getEnv("ZOOKEEPER_SCHEMA", Config.Zookeeper.Schema) Config.Zookeeper.Username = getEnv("ZOOKEEPER_USERNAME", Config.Zookeeper.Username) Config.Zookeeper.Password = getEnv("ZOOKEEPER_PASSWORD", Config.Zookeeper.Password) - Config.Zookeeper.ZkAddr = getArrEnv("ZOOKEEPER_ADDRESS", "ZOOKEEPER_PORT", Config.Zookeeper.ZkAddr) Config.ChatApi.ListenIP = getEnv("CHAT_API_LISTEN_IP", Config.ChatApi.ListenIP) Config.AdminApi.ListenIP = getEnv("ADMIN_API_LISTEN_IP", Config.AdminApi.ListenIP) @@ -253,18 +251,21 @@ func configGetEnv() error { if err != nil { return err } - + getArrEnv("ZOOKEEPER_ADDRESS", "ZOOKEEPER_PORT", Config.Zookeeper.ZkAddr) return nil } -func getArrEnv(key1, key2 string, fallback []string) []string { +func getArrEnv(key1, key2 string, fallback []string) { str1 := getEnv(key1, "") str2 := getEnv(key2, "") str := fmt.Sprintf("%s:%s", str1, str2) + arr := make([]string, 1) if len(str) <= 1 { - return fallback + return } - return []string{str} + arr[0] = str + fmt.Println("zookeeper Envirement valiable", "str", str) + Config.Zookeeper.ZkAddr = arr } func getArrPointEnv(key1, key2 string, fallback *[]string) *[]string {