MCPcopy
hub / github.com/openimsdk/open-im-server / readConfig

Function readConfig

tools/seq/internal/main.go:46–66  ·  view source on GitHub ↗
(dir string, name string)

Source from the content-addressed store, hash-verified

44)
45
46func readConfig[T any](dir string, name string) (*T, error) {
47 if runtimeenv.RuntimeEnvironment() == config.KUBERNETES {
48 dir = os.Getenv(config.MountConfigFilePath)
49 }
50 v := viper.New()
51 v.SetEnvPrefix(config.EnvPrefixMap[name])
52 v.AutomaticEnv()
53 v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
54 v.SetConfigFile(filepath.Join(dir, name))
55 if err := v.ReadInConfig(); err != nil {
56 return nil, err
57 }
58 fn := func(config *mapstructure.DecoderConfig) {
59 config.TagName = "mapstructure"
60 }
61 var conf T
62 if err := v.Unmarshal(&conf, fn); err != nil {
63 return nil, err
64 }
65 return &conf, nil
66}
67
68func Main(conf string, del time.Duration) error {
69 redisConfig, err := readConfig[config.Redis](conf, cmd.RedisConfigFileName)

Callers 1

MainFunction · 0.85

Calls 1

UnmarshalMethod · 0.80

Tested by

no test coverage detected