1
0
Fork 0

Add defer Close() for configFile. A more clear error message for yaml decoder. And a comment for SplitNetworkAddress method.

This commit is contained in:
Alexander Andreev 2022-02-07 18:21:40 +04:00
parent c3e81c61d7
commit 64ab7e5d40
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
1 changed files with 5 additions and 1 deletions

View File

@ -29,16 +29,20 @@ func LoadConfiguration(path string) (*Configuration, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to open configuration file")
}
defer configFile.Close()
config := &Configuration{}
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
}
// 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) {
s := strings.Split(c.ListenOn, " ")
n, a = s[0], s[1]