From 22d19fd6b71dffec8cab97ded1d203e8b4f1880f Mon Sep 17 00:00:00 2001 From: chao <48119764+withchao@users.noreply.github.com> Date: Mon, 10 Feb 2025 11:44:57 +0800 Subject: [PATCH] fix: seq conversion not reading env in docker environment (#3130) * pb * fix: Modifying other fields while setting IsPrivateChat does not take effect * fix: quote message error revoke * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * upgrading pkg tools * fix * fix * optimize log output * feat: support GetLastMessage * feat: support GetLastMessage * feat: s3 switch * feat: s3 switch * fix: GetUsersOnline * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: seq conversion failed without exiting * fix: DeleteDoc crash * fix: fill send time * fix: fill send time * fix: crash caused by withdrawing messages from users who have left the group * fix: user msg timestamp * seq read config * seq read config --- tools/seq/internal/main.go | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tools/seq/internal/main.go b/tools/seq/internal/main.go index 2bec5a8f1..a19f6a721 100644 --- a/tools/seq/internal/main.go +++ b/tools/seq/internal/main.go @@ -5,16 +5,6 @@ import ( "context" "errors" "fmt" - "github.com/openimsdk/open-im-server/v3/pkg/common/cmd" - "github.com/openimsdk/open-im-server/v3/pkg/common/config" - "github.com/openimsdk/open-im-server/v3/pkg/common/storage/database/mgo" - "github.com/openimsdk/tools/db/mongoutil" - "github.com/openimsdk/tools/db/redisutil" - "github.com/redis/go-redis/v9" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" - "gopkg.in/yaml.v3" "os" "os/signal" "path/filepath" @@ -24,6 +14,17 @@ import ( "sync/atomic" "syscall" "time" + + "github.com/mitchellh/mapstructure" + "github.com/openimsdk/open-im-server/v3/pkg/common/config" + "github.com/openimsdk/open-im-server/v3/pkg/common/storage/database/mgo" + "github.com/openimsdk/tools/db/mongoutil" + "github.com/openimsdk/tools/db/redisutil" + "github.com/redis/go-redis/v9" + "github.com/spf13/viper" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" ) const ( @@ -41,12 +42,22 @@ const ( ) func readConfig[T any](dir string, name string) (*T, error) { - data, err := os.ReadFile(filepath.Join(dir, name)) - if err != nil { + if runtimeenv.PrintRuntimeEnvironment() == config.KUBERNETES { + dir = os.Getenv(config.MountConfigFilePath) + } + v := viper.New() + v.SetEnvPrefix(config.EnvPrefixMap[name]) + v.AutomaticEnv() + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + v.SetConfigFile(filepath.Join(dir, name)) + if err := v.ReadInConfig(); err != nil { return nil, err } + fn := func(config *mapstructure.DecoderConfig) { + config.TagName = "mapstructure" + } var conf T - if err := yaml.Unmarshal(data, &conf); err != nil { + if err := v.Unmarshal(&conf, fn); err != nil { return nil, err } return &conf, nil