package acmedns import ( "errors" "os" "github.com/BurntSushi/toml" ) func FileIsAccessible(fname string) bool { _, err := os.Stat(fname) if err != nil { return false } f, err := os.Open(fname) if err != nil { return false } f.Close() return true } func ReadConfig(fname string) (AcmeDnsConfig, error) { var conf AcmeDnsConfig _, err := toml.DecodeFile(fname, &conf) if err != nil { // Return with config file parsing errors from toml package return conf, err } return prepareConfig(conf) } // prepareConfig checks that mandatory values exist, and can be used to set default values in the future func prepareConfig(conf AcmeDnsConfig) (AcmeDnsConfig, error) { if conf.Database.Engine == "" { return conf, errors.New("missing database configuration option \"engine\"") } if conf.Database.Connection == "" { return conf, errors.New("missing database configuration option \"connection\"") } // Default values for options added to config to keep backwards compatibility with old config if conf.API.ACMECacheDir == "" { conf.API.ACMECacheDir = "api-certs" } return conf, nil }