diff --git a/cmd/api/main.go b/cmd/api/main.go index 079747003..277e0d47b 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "context" "fmt" "net" @@ -10,8 +9,6 @@ import ( "strconv" "time" - "gopkg.in/yaml.v3" - "net/http" _ "net/http/pprof" @@ -61,12 +58,8 @@ func run(port int) error { return err } fmt.Println("api init discov client success") - buf := bytes.NewBuffer(nil) - if err := yaml.NewEncoder(buf).Encode(config.Config); err != nil { - return err - } fmt.Println("api register public config to discov") - if err := client.RegisterConf2Registry(constant.OpenIMCommonConfigKey, buf.Bytes()); err != nil { + if err := client.RegisterConf2Registry(constant.OpenIMCommonConfigKey, config.EncodeConfig()); err != nil { return err } fmt.Println("api register public config to discov success") diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 651fcc902..4c43096f7 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -1,6 +1,7 @@ package config import ( + "bytes" "fmt" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" @@ -96,3 +97,11 @@ func InitConfig(configFolderPath string) error { } return nil } + +func EncodeConfig() []byte { + buf := bytes.NewBuffer(nil) + if err := yaml.NewEncoder(buf).Encode(Config); err != nil { + panic(err) + } + return buf.Bytes() +}