From 64ab7e5d404572f6250ac50f23a4cc67ea488ced Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 7 Feb 2022 18:21:40 +0400 Subject: [PATCH] Add defer Close() for configFile. A more clear error message for yaml decoder. And a comment for SplitNetworkAddress method. --- internal/configuration/configuration.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/configuration/configuration.go b/internal/configuration/configuration.go index ac29a01..be7bc59 100644 --- a/internal/configuration/configuration.go +++ b/internal/configuration/configuration.go @@ -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]