Add defer Close() for configFile. A more clear error message for yaml decoder. And a comment for SplitNetworkAddress method.
This commit is contained in:
parent
c3e81c61d7
commit
64ab7e5d40
@ -29,16 +29,20 @@ func LoadConfiguration(path string) (*Configuration, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to open configuration file")
|
return nil, errors.Wrap(err, "failed to open configuration file")
|
||||||
}
|
}
|
||||||
|
defer configFile.Close()
|
||||||
|
|
||||||
config := &Configuration{}
|
config := &Configuration{}
|
||||||
|
|
||||||
if err := yaml.NewDecoder(configFile).Decode(config); err != nil {
|
if err := yaml.NewDecoder(configFile).Decode(config); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to decode configuration file")
|
return nil, errors.Wrap(err, "failed to parse configuration file")
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SplitNetworkAddress splits ListenOn option and returns as two strings
|
||||||
|
// network type (e.g. tcp, unix, udp) and address:port or /path/to/prog.socket
|
||||||
|
// to listen on.
|
||||||
func (c *Configuration) SplitNetworkAddress() (n string, a string) {
|
func (c *Configuration) SplitNetworkAddress() (n string, a string) {
|
||||||
s := strings.Split(c.ListenOn, " ")
|
s := strings.Split(c.ListenOn, " ")
|
||||||
n, a = s[0], s[1]
|
n, a = s[0], s[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user