FIX ParseConf returned invalid conf
This commit is contained in:
parent
f83cc1b1ef
commit
5d6db07758
2 changed files with 17 additions and 6 deletions
|
@ -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)
|
||||
|
|
21
confload.go
21
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue