megauploader/confload.go

38 lines
756 B
Go
Raw Normal View History

2017-09-23 19:46:58 +02:00
package megauploader
import (
"io/ioutil"
"os"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
)
2018-01-05 22:23:52 +01:00
// ParseConfFile will read and load a config file
func ParseConfFile(filename string) (Config, error) {
2017-09-23 19:46:58 +02:00
buf, err := os.Open(filename)
if err != nil {
return Config{}, errors.Wrap(err, "Error opening config file")
}
defer buf.Close()
content, err := ioutil.ReadAll(buf)
if err != nil {
return Config{}, errors.Wrap(err, "Error reading config file")
}
2018-01-05 22:23:52 +01:00
return ParseConf(content)
}
// ParseConf will parse configuration content
func ParseConf(content []byte) (Config, error) {
2017-09-23 19:46:58 +02:00
var c Config
2018-01-05 22:23:52 +01:00
err := yaml.UnmarshalStrict(content, &c)
if err != nil {
return c, err
}
if c.UserHome == nil {
c.UserHome = new(UserHome)
}
return c, nil
2017-09-23 19:46:58 +02:00
}