Remove juju/errors

This commit is contained in:
9seconds
2019-09-06 16:10:55 +03:00
parent 701f62ed4c
commit 2918ed11e5
19 changed files with 73 additions and 91 deletions
+4 -3
View File
@@ -4,11 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net"
"strconv"
"time"
"github.com/juju/errors"
"go.uber.org/zap"
statsd "gopkg.in/alexcesaro/statsd.v2"
)
@@ -187,7 +188,7 @@ func Init(options ...Opt) error { // nolint: gocyclo
case "influxdb":
C.StatsdStats.TagsFormat = statsd.InfluxDB
default:
return errors.Errorf("Incorrect statsd tag %s", value)
return fmt.Errorf("Incorrect statsd tag %s", value)
}
case OptionTypeStatsdTags:
C.StatsdStats.Tags = opt.Value.(map[string]string)
@@ -206,7 +207,7 @@ func Init(options ...Opt) error { // nolint: gocyclo
case OptionTypeAdtag:
C.AdTag = opt.Value.([]byte)
default:
return errors.Errorf("Unknown tag %v", opt.Option)
return fmt.Errorf("Unknown tag %v", opt.Option)
}
}
+7 -8
View File
@@ -2,14 +2,13 @@ package config
import (
"context"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"strings"
"time"
"github.com/juju/errors"
)
const (
@@ -20,7 +19,7 @@ const (
func getGlobalIPv4(ctx context.Context) (net.IP, error) {
ip, err := fetchIP(ctx, "tcp4")
if err != nil || ip.To4() == nil {
return nil, errors.Annotate(err, "Cannot find public ipv4 address")
return nil, fmt.Errorf("cannot find public ipv4 address: %w", err)
}
return ip, nil
}
@@ -28,7 +27,7 @@ func getGlobalIPv4(ctx context.Context) (net.IP, error) {
func getGlobalIPv6(ctx context.Context) (net.IP, error) {
ip, err := fetchIP(ctx, "tcp6")
if err != nil || ip.To4() != nil {
return nil, errors.Annotate(err, "Cannot find public ipv6 address")
return nil, fmt.Errorf("cannot find public ipv6 address: %w", err)
}
return ip, nil
}
@@ -47,7 +46,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
req, err := http.NewRequest("GET", ifconfigAddress, nil)
if err != nil {
return nil, errors.Annotate(err, "Cannot create a request")
return nil, fmt.Errorf("cannot create a request: %w", err)
}
resp, err := client.Do(req.WithContext(ctx))
@@ -55,19 +54,19 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
if resp != nil {
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck
}
return nil, errors.Annotate(err, "Cannot perform a request")
return nil, fmt.Errorf("cannot perform a request: %w", err)
}
defer resp.Body.Close() // nolint: errcheck
respDataBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errors.Annotate(err, "Cannot read response body")
return nil, fmt.Errorf("cannot read response body: %w", err)
}
respData := strings.TrimSpace(string(respDataBytes))
ip := net.ParseIP(respData)
if ip == nil {
return nil, errors.Errorf("ifconfig.co returns incorrect IP %s", respData)
return nil, fmt.Errorf("ifconfig.co returns incorrect IP %s", respData)
}
return ip, nil