diff --git a/cmd/api/admin-api/main.go b/cmd/api/admin-api/main.go index e9cb6baba..6fe354475 100644 --- a/cmd/api/admin-api/main.go +++ b/cmd/api/admin-api/main.go @@ -25,7 +25,7 @@ import ( mw2 "github.com/OpenIMSDK/chat/pkg/common/mw" "github.com/OpenIMSDK/chat/internal/api" - "github.com/OpenIMSDK/chat/pkg/common/config" + "github.com/OpenIMSDK/chat/pkg/common/config_fixed" openKeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mw" diff --git a/cmd/api/chat-api/main.go b/cmd/api/chat-api/main.go index ef3632c78..aa6000769 100644 --- a/cmd/api/chat-api/main.go +++ b/cmd/api/chat-api/main.go @@ -28,7 +28,7 @@ import ( mw2 "github.com/OpenIMSDK/chat/pkg/common/mw" "github.com/OpenIMSDK/chat/internal/api" - "github.com/OpenIMSDK/chat/pkg/common/config" + "github.com/OpenIMSDK/chat/pkg/common/config_fixed" openKeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mw" diff --git a/cmd/rpc/admin-rpc/main.go b/cmd/rpc/admin-rpc/main.go index 32391f3ed..504fa81ef 100644 --- a/cmd/rpc/admin-rpc/main.go +++ b/cmd/rpc/admin-rpc/main.go @@ -23,7 +23,7 @@ import ( "time" "github.com/OpenIMSDK/chat/internal/rpc/admin" - "github.com/OpenIMSDK/chat/pkg/common/config" + "github.com/OpenIMSDK/chat/pkg/common/config_fixed" ) func main() { diff --git a/cmd/rpc/chat-rpc/main.go b/cmd/rpc/chat-rpc/main.go index 50de20a67..2da70ba3e 100644 --- a/cmd/rpc/chat-rpc/main.go +++ b/cmd/rpc/chat-rpc/main.go @@ -23,7 +23,7 @@ import ( "time" "github.com/OpenIMSDK/chat/internal/rpc/chat" - "github.com/OpenIMSDK/chat/pkg/common/config" + "github.com/OpenIMSDK/chat/pkg/common/config_fixed" ) func main() { diff --git a/pkg/common/config/im.go b/pkg/common/config/im.go index 6751d8b83..34ca36486 100644 --- a/pkg/common/config/im.go +++ b/pkg/common/config/im.go @@ -14,7 +14,9 @@ package config -var imConfig struct { +func init() { + func init() { + var imConfig struct { Mysql struct { Address []string `yaml:"address"` Username string `yaml:"username"` diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index f6bd7fcd8..93781139b 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -35,7 +35,11 @@ var ( Root = filepath.Join(filepath.Dir(b), "../../..") ) -func readConfig(configFile string) ([]byte, error) { +// Added variable declarations inside the function body +func InitConfig(configFile string) error { + _, b, _, _ := runtime.Caller(0) + // Root folder of this project. + Root := filepath.Join(filepath.Dir(b), "../../..") b, err := os.ReadFile(configFile) if err != nil { return nil, utils.Wrap(err, configFile) diff --git a/tools/component/component.go b/tools/component/component.go index 3f28862f5..7b76c0ee0 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -2,7 +2,7 @@ package component import ( "fmt" - "github.com/OpenIMSDK/chat/pkg/common/config" + "github.com/OpenIMSDK/chat/pkg/common/config_fixed" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log"