diff options
author | Alan Pearce | 2024-05-22 18:03:22 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-22 18:03:22 +0200 |
commit | ea098ab11740fe4783694ff0122738b30e0c342f (patch) | |
tree | bcd50fdb6fc7ce9730c758f709aa6bf29a763ea9 /internal/config/config.go | |
parent | aef028263229d8acda28b8e657413f7e9c187833 (diff) | |
download | website-ea098ab11740fe4783694ff0122738b30e0c342f.tar.lz website-ea098ab11740fe4783694ff0122738b30e0c342f.tar.zst website-ea098ab11740fe4783694ff0122738b30e0c342f.zip |
refactor: lint with golangci-lint
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index be7dcb9..df69bce 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -25,7 +25,8 @@ type URL struct { func (u *URL) UnmarshalText(text []byte) (err error) { u.URL, err = url.Parse(string(text)) - return err + + return errors.Wrapf(err, "could not parse URL %s", string(text)) } type Config struct { @@ -51,15 +52,15 @@ func GetConfig() (*Config, error) { log.Debug("reading config.toml") _, err := toml.DecodeFile("config.toml", &config) if err != nil { - var pathError *fs.PathError - var tomlError toml.ParseError - if errors.As(err, &pathError) { - return nil, errors.WithMessage(err, "could not read configuration") - } else if errors.As(err, &tomlError) { - return nil, errors.WithMessage(err, tomlError.ErrorWithUsage()) - } else { - return nil, errors.Wrap(err, "config error") + switch t := err.(type) { + case *fs.PathError: + return nil, errors.WithMessage(t, "could not read configuration") + case *toml.ParseError: + return nil, errors.WithMessage(t, t.ErrorWithUsage()) } + + return nil, errors.Wrap(err, "config error") } + return &config, nil } |