diff --git a/cmd/megauploader/main.go b/cmd/megauploader/main.go index aa2e29e..0f7cbca 100644 --- a/cmd/megauploader/main.go +++ b/cmd/megauploader/main.go @@ -17,7 +17,7 @@ func main() { addr := flag.String("addr", "localhost:8000", "Listen address") flag.Parse() - cfg, err := megauploader.ParseConf(*cfgfile) + cfg, err := megauploader.ParseConfFile(*cfgfile) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/confload.go b/confload.go index d5b83f9..2651f6b 100644 --- a/confload.go +++ b/confload.go @@ -9,8 +9,8 @@ import ( yaml "gopkg.in/yaml.v2" ) -// ParseConf will read and load a config file -func ParseConf(filename string) (Config, error) { +// ParseConfFile will read and load a config file +func ParseConfFile(filename string) (Config, error) { buf, err := os.Open(filename) if err != nil { return Config{}, errors.Wrap(err, "Error opening config file") @@ -20,7 +20,18 @@ func ParseConf(filename string) (Config, error) { if err != nil { return Config{}, errors.Wrap(err, "Error reading config file") } - var c Config - err = yaml.UnmarshalStrict(content, &c) - return c, err + return ParseConf(content) +} + +// ParseConf will parse configuration content +func ParseConf(content []byte) (Config, error) { + var c Config + err := yaml.UnmarshalStrict(content, &c) + if err != nil { + return c, err + } + if c.UserHome == nil { + c.UserHome = new(UserHome) + } + return c, nil }