dyndns/service/userconfig.go
Torben Nehmer 9f1b9f1690 Refactorization and further implementation
- renamed clientoinfo to updaterequest
- added userconfig skeleton
- added hashed password skeleton
2021-08-21 20:35:08 +02:00

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
}