linting the code

This commit is contained in:
9seconds
2019-10-11 09:41:18 +03:00
parent 432e2970a0
commit 5009859a1e
50 changed files with 172 additions and 55 deletions
+8 -4
View File
@@ -23,6 +23,7 @@ func (s SecretMode) String() string {
case SecretModeSecured:
return "secured"
}
return "tls"
}
@@ -135,7 +136,7 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
case "influxdb":
C.StatsdTagsFormat = statsd.InfluxDB
default:
return fmt.Errorf("Incorrect statsd tag %s", value)
return fmt.Errorf("incorrect statsd tag %s", value)
}
case OptionTypeStatsdTags:
C.StatsdTags = opt.Value.(map[string]string)
@@ -152,7 +153,7 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
case OptionTypeAdtag:
C.AdTag = opt.Value.([]byte)
default:
return fmt.Errorf("Unknown tag %v", opt.Option)
return fmt.Errorf("unknown tag %v", opt.Option)
}
}
@@ -163,7 +164,7 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
case len(C.Secret) == SimpleSecretLength:
C.SecretMode = SecretModeSimple
default:
return errors.New("Incorrect secret")
return errors.New("incorrect secret")
}
return nil
@@ -173,11 +174,13 @@ func InitPublicAddress(ctx context.Context) error {
if C.PublicIPv4.Port == 0 {
C.PublicIPv4.Port = C.Bind.Port
}
if C.PublicIPv6.Port == 0 {
C.PublicIPv6.Port = C.Bind.Port
}
foundAddress := C.PublicIPv4.IP != nil || C.PublicIPv6.IP != nil
if C.PublicIPv4.IP == nil {
ip, err := getGlobalIPv4(ctx)
if err != nil {
@@ -187,6 +190,7 @@ func InitPublicAddress(ctx context.Context) error {
foundAddress = true
}
}
if C.PublicIPv6.IP == nil {
ip, err := getGlobalIPv6(ctx)
if err != nil {
@@ -198,7 +202,7 @@ func InitPublicAddress(ctx context.Context) error {
}
if !foundAddress {
return errors.New("Cannot resolve any public address")
return errors.New("cannot resolve any public address")
}
return nil
+5
View File
@@ -21,6 +21,7 @@ func getGlobalIPv4(ctx context.Context) (net.IP, error) {
if err != nil || ip.To4() == nil {
return nil, fmt.Errorf("cannot find public ipv4 address: %w", err)
}
return ip, nil
}
@@ -29,6 +30,7 @@ func getGlobalIPv6(ctx context.Context) (net.IP, error) {
if err != nil || ip.To4() != nil {
return nil, fmt.Errorf("cannot find public ipv6 address: %w", err)
}
return ip, nil
}
@@ -54,14 +56,17 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
if resp != nil {
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck
}
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, fmt.Errorf("cannot read response body: %w", err)
}
respData := strings.TrimSpace(string(respDataBytes))
ip := net.ParseIP(respData)
+1
View File
@@ -22,6 +22,7 @@ type IPURLs struct {
func GetURLs() (urls IPURLs) {
secret := ""
switch C.SecretMode {
case SecretModeSimple:
secret = hex.EncodeToString(C.Secret)