mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-27 05:52:29 +08:00 
			
		
		
		
	* 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 * monolithic * fix: DeleteDoc crash * fix: DeleteDoc crash * fix: monolithic * fix: monolithic * fix: fill send time * fix: fill send time * fix: crash caused by withdrawing messages from users who have left the group * fix: mq * fix: mq * fix: user msg timestamp * fix: mq * 1 * 1 * 1 * 1 * 1 * 1 * 1 * seq read config * seq read config * 1 * 1 * fix: the source message of the reference is withdrawn, and the referenced message is deleted * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package config
 | |
| 
 | |
| import (
 | |
| 	"os"
 | |
| 	"path/filepath"
 | |
| 	"strings"
 | |
| 
 | |
| 	"github.com/mitchellh/mapstructure"
 | |
| 	"github.com/openimsdk/tools/errs"
 | |
| 	"github.com/openimsdk/tools/utils/runtimeenv"
 | |
| 	"github.com/spf13/viper"
 | |
| )
 | |
| 
 | |
| func Load(configDirectory string, configFileName string, envPrefix string, config any) error {
 | |
| 	if runtimeenv.RuntimeEnvironment() == KUBERNETES {
 | |
| 		mountPath := os.Getenv(MountConfigFilePath)
 | |
| 		if mountPath == "" {
 | |
| 			return errs.ErrArgs.WrapMsg(MountConfigFilePath + " env is empty")
 | |
| 		}
 | |
| 
 | |
| 		return loadConfig(filepath.Join(mountPath, configFileName), envPrefix, config)
 | |
| 	}
 | |
| 
 | |
| 	return loadConfig(filepath.Join(configDirectory, configFileName), envPrefix, config)
 | |
| }
 | |
| 
 | |
| func loadConfig(path string, envPrefix string, config any) error {
 | |
| 	v := viper.New()
 | |
| 	v.SetConfigFile(path)
 | |
| 	v.SetEnvPrefix(envPrefix)
 | |
| 	v.AutomaticEnv()
 | |
| 	v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
 | |
| 
 | |
| 	if err := v.ReadInConfig(); err != nil {
 | |
| 		return errs.WrapMsg(err, "failed to read config file", "path", path, "envPrefix", envPrefix)
 | |
| 	}
 | |
| 
 | |
| 	if err := v.Unmarshal(config, func(config *mapstructure.DecoderConfig) {
 | |
| 		config.TagName = StructTagName
 | |
| 	}); err != nil {
 | |
| 		return errs.WrapMsg(err, "failed to unmarshal config", "path", path, "envPrefix", envPrefix)
 | |
| 	}
 | |
| 	return nil
 | |
| }
 |