From 4ba776847f9b3ef344766be15482e88a14034921 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw)" <3293172751nss@gmail.com> Date: Tue, 19 Dec 2023 10:52:25 +0800 Subject: [PATCH] feat: set openim lint Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> --- deployments/templates/config.yaml | 8 ++++---- pkg/common/config/version | 2 +- tools/component/component.go | 26 +++++++++++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/deployments/templates/config.yaml b/deployments/templates/config.yaml index 648dcc280..798677027 100644 --- a/deployments/templates/config.yaml +++ b/deployments/templates/config.yaml @@ -20,7 +20,7 @@ envs: zookeeper: schema: openim # ZOOKEEPER_SCHEMA, the schema to use in Zookeeper zkAddr: - - 127.28.0.1:12181 # ZOOKEEPER_ADDRESS and ZOOKEEPER_PORT, Zookeeper address and port + - 172.28.0.1:12181 # ZOOKEEPER_ADDRESS and ZOOKEEPER_PORT, Zookeeper address and port username: "" # ZOOKEEPER_USERNAME, Username for Zookeeper authentication password: "" # ZOOKEEPER_PASSWORD, Password for Zookeeper authentication @@ -51,7 +51,7 @@ rpcRegisterName: # MySQL database configuration - used for storing OpenIM data mysql: - address: [ 127.0.0.1:13306 ] # MYSQL_ADDRESS and MYSQL_PORT, MySQL server address and port + address: [ 172.28.0.1:13306 ] # MYSQL_ADDRESS and MYSQL_PORT, MySQL server address and port username: root # MYSQL_USERNAME, Username for MySQL password: openIM123 # MYSQL_PASSWORD, Password for MySQL database: openIM_v3 # MYSQL_DATABASE, Database name @@ -118,10 +118,10 @@ adminList: imAdmin: openIMAdmin # URL for OpenIM server -openIMUrl: "127.0.0.1:10002" # OPENIM_SERVER_ADDRESS:API_OPENIM_PORT, URL of the OpenIM server +openIMUrl: "172.28.0.1:10002" # OPENIM_SERVER_ADDRESS:API_OPENIM_PORT, URL of the OpenIM server # Redis configuration - used for caching and session management redis: - address: [ 127.0.0.1:16379 ] # REDIS_ADDRESS and REDIS_PORT, Redis server address and port + address: [ 172.28.0.1:16379 ] # REDIS_ADDRESS and REDIS_PORT, Redis server address and port username: # REDIS_USERNAME, Username for Redis authentication password: openIM123 # REDIS_PASSWORD, Password for Redis diff --git a/pkg/common/config/version b/pkg/common/config/version index 56e50151c..7c7d607d3 100644 --- a/pkg/common/config/version +++ b/pkg/common/config/version @@ -1 +1 @@ -v3.3.1 \ No newline at end of file +v3.3.5 \ No newline at end of file diff --git a/tools/component/component.go b/tools/component/component.go index f7e37bca4..3bf40987b 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -16,10 +16,11 @@ package component import ( "fmt" - "github.com/OpenIMSDK/protocol/constant" "os" "time" + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/chat/pkg/common/config" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" @@ -28,6 +29,10 @@ import ( "gopkg.in/yaml.v3" ) +var ( + MaxConnectTimes = 100 +) + func initCfg(cfgPath string) error { file, err := os.ReadFile(cfgPath) if err != nil { @@ -47,15 +52,14 @@ func ComponentCheck(cfgPath string, hide bool) error { return err } if config.Config.Envs.Discovery != "k8s" { - var zkConn *zk.Conn - if zkConn, err = checkNewZkClient(hide); err != nil { - errorPrint(fmt.Sprintf("%v.Please check if your openIM server has started", err.Error()), hide) - return err - } - if err = checkGetCfg(zkConn, hide); err != nil { + if _, err := checkNewZkClient(hide); err != nil { errorPrint(fmt.Sprintf("%v.Please check if your openIM server has started", err.Error()), hide) return err } + // if err = checkGetCfg(zkConn, hide); err != nil { + // errorPrint(fmt.Sprintf("%v.Please check if your openIM server has started", err.Error()), hide) + // return err + // } } return nil @@ -76,7 +80,9 @@ func successPrint(s string, hide bool) { func newZkClient() (*zk.Conn, error) { var c *zk.Conn c, _, err := zk.Connect(config.Config.Zookeeper.ZkAddr, time.Second, zk.WithLogger(log.NewZkLogger())) + fmt.Println("zk addr=", config.Config.Zookeeper.ZkAddr) if err != nil { + fmt.Println("zookeeper connect error:", err) return nil, errs.Wrap(err) } else { if config.Config.Zookeeper.Username != "" && config.Config.Zookeeper.Password != "" { @@ -89,7 +95,7 @@ func newZkClient() (*zk.Conn, error) { } func checkNewZkClient(hide bool) (*zk.Conn, error) { - for i := 0; i < 100; i++ { + for i := 0; i < MaxConnectTimes; i++ { if i != 0 { time.Sleep(3 * time.Second) } @@ -108,13 +114,15 @@ func checkNewZkClient(hide bool) (*zk.Conn, error) { } func checkGetCfg(conn *zk.Conn, hide bool) error { - for i := 0; i < 100; i++ { + for i := 0; i < MaxConnectTimes; i++ { if i != 0 { time.Sleep(3 * time.Second) } path := "/" + config.Config.Zookeeper.Schema + "/" + constant.OpenIMCommonConfigKey + zkConfig, _, err := conn.Get(path) if err != nil { + fmt.Println("path =", path, "zkConfig is:", zkConfig) errorPrint(fmt.Sprintf("! get zk config [%d] error: %v\n", i, err), hide) continue } else if len(zkConfig) == 0 {