Error out if unknown properties are found in the config file

And thanks to this, an inconsistency in the example config file vs the parser
was found (`timeout` vs `timeout_ms`).

Fixes #113
This commit is contained in:
Frank Denis 2018-02-10 21:19:40 +01:00
parent 32db89d2ee
commit 2f00ad5ff0
1 changed files with 7 additions and 2 deletions

View File

@ -23,7 +23,7 @@ type Config struct {
ListenAddresses []string `toml:"listen_addresses"`
Daemonize bool
ForceTCP bool `toml:"force_tcp"`
Timeout int `toml:"timeout_ms"`
Timeout int `toml:"timeout"`
CertRefreshDelay int `toml:"cert_refresh_delay"`
CertIgnoreTimestamp bool `toml:"cert_ignore_timestamp"`
LBStrategy string `toml:"lb_strategy"`
@ -148,9 +148,14 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
os.Exit(0)
}
config := newConfig()
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
md, err := toml.DecodeFile(*configFile, &config)
if err != nil {
return err
}
undecoded := md.Undecoded()
if len(undecoded) > 0 {
return fmt.Errorf("Unsupported key in configuration file: [%s]", undecoded[0])
}
cdFileDir(*configFile)
if config.LogLevel >= 0 && config.LogLevel < int(dlog.SeverityLast) {
dlog.SetLogLevel(dlog.Severity(config.LogLevel))