package service import ( "fmt" "log" "os" "path" "github.com/spf13/viper" ) func LoadConfigForUser(username string) (*viper.Viper, error) { configFile := fmt.Sprintf("%s/%s.yml", C.UsersConfigDir, username) configFile = path.Clean(configFile) log.Printf("Trying to load config file %s for user %s", configFile, username) if _, err := os.Stat(configFile); err != nil { return nil, fmt.Errorf("cannot stat the file %s: %v", configFile, err) } v := viper.New() v.SetConfigFile(configFile) err := v.ReadInConfig() if err != nil { return nil, fmt.Errorf("failed to parse config file %s: %v", configFile, err) } return v, nil }