print default values on error
This commit is contained in:
parent
46207396ef
commit
924d9d4df7
15
envconf.go
15
envconf.go
@ -91,17 +91,28 @@ func (c *Config) Parse() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.parsed = true
|
c.parsed = true
|
||||||
|
failed := false
|
||||||
for k, v := range c.env {
|
for k, v := range c.env {
|
||||||
if v.empty {
|
if v.empty {
|
||||||
if v.unset {
|
if v.unset {
|
||||||
v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. It should have been of type %s.`, k, v.dtype))
|
failed = true
|
||||||
c.env[k] = v
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
v.parsed = v.dtype.parse(k, v.value)
|
v.parsed = v.dtype.parse(k, v.value)
|
||||||
c.env[k] = v
|
c.env[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for k, v := range c.env {
|
||||||
|
if failed && (v.parsed.err == nil) {
|
||||||
|
if v.unset {
|
||||||
|
v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. It should have been of type %s.`, k, v.dtype))
|
||||||
|
c.env[k] = v
|
||||||
|
} else {
|
||||||
|
v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. Default value of "%s"(%s) used.`, k, v.value, v.dtype))
|
||||||
|
c.env[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status prints out failures that occured while parsing the environment to os.Stderr.
|
// Status prints out failures that occured while parsing the environment to os.Stderr.
|
||||||
|
Loading…
Reference in New Issue
Block a user