Torben Nehmer
9f1b9f1690
- renamed clientoinfo to updaterequest - added userconfig skeleton - added hashed password skeleton
31 lines
649 B
Go
31 lines
649 B
Go
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
|
|
}
|