Use errors.Wrap instead of manual formatting

This commit is contained in:
kaiyou 2020-05-10 18:23:46 +02:00 committed by Leo Antunes
parent 32a300ffeb
commit c50011bc36
1 changed files with 3 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/costela/wesher/cluster" "github.com/costela/wesher/cluster"
"github.com/hashicorp/go-sockaddr" "github.com/hashicorp/go-sockaddr"
"github.com/pkg/errors"
"github.com/stevenroose/gonfig" "github.com/stevenroose/gonfig"
) )
@ -50,11 +51,11 @@ func loadConfig() (*config, error) {
// Compute the actual bind address based on the provided interface // Compute the actual bind address based on the provided interface
iface, err := net.InterfaceByName(config.BindIface) iface, err := net.InterfaceByName(config.BindIface)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not get interface by name %s: %w", config.BindIface, err) return nil, errors.Wrapf(err, "could not get interface by name %s", config.BindIface)
} }
addrs, err := iface.Addrs() addrs, err := iface.Addrs()
if err != nil { if err != nil {
return nil, fmt.Errorf("could not get addresses for interface %s: %w", config.BindIface, err) return nil, errors.Wrapf(err, "could not get addresses for interface %s", config.BindIface)
} }
if len(addrs) > 0 { if len(addrs) > 0 {
if addr, ok := addrs[0].(*net.IPNet); ok { if addr, ok := addrs[0].(*net.IPNet); ok {