|
|
@ -15,16 +15,17 @@ import (
|
|
|
|
"syscall"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
"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/open-im-server/v3/pkg/common/storage/database/mgo"
|
|
|
|
"github.com/openimsdk/tools/db/mongoutil"
|
|
|
|
"github.com/openimsdk/tools/db/mongoutil"
|
|
|
|
"github.com/openimsdk/tools/db/redisutil"
|
|
|
|
"github.com/openimsdk/tools/db/redisutil"
|
|
|
|
"github.com/openimsdk/tools/utils/runtimeenv"
|
|
|
|
"github.com/openimsdk/tools/utils/runtimeenv"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
@ -45,13 +46,16 @@ func readConfig[T any](dir string, name string) (*T, error) {
|
|
|
|
if runtimeenv.PrintRuntimeEnvironment() == config.KUBERNETES {
|
|
|
|
if runtimeenv.PrintRuntimeEnvironment() == config.KUBERNETES {
|
|
|
|
dir = os.Getenv(config.MountConfigFilePath)
|
|
|
|
dir = os.Getenv(config.MountConfigFilePath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v := viper.New()
|
|
|
|
data, err := os.ReadFile(filepath.Join(dir, name))
|
|
|
|
v.SetConfigFile(filepath.Join(dir, name))
|
|
|
|
if err != nil {
|
|
|
|
if err := v.ReadInConfig(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn := func(config *mapstructure.DecoderConfig) {
|
|
|
|
|
|
|
|
config.TagName = "mapstructure"
|
|
|
|
|
|
|
|
}
|
|
|
|
var conf T
|
|
|
|
var conf T
|
|
|
|
if err := yaml.Unmarshal(data, &conf); err != nil {
|
|
|
|
if err := v.Unmarshal(&conf, fn); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &conf, nil
|
|
|
|
return &conf, nil
|
|
|
|