From 029060a6a166bf0d5b37175b551af34da0b0f6dc Mon Sep 17 00:00:00 2001 From: Ben Cartwright-Cox Date: Thu, 19 Jan 2023 12:11:02 +0000 Subject: [PATCH] Replace redudant errors.new(fmt.sprintf with fmt.errorf( They serve the same function, but it's more understandable what is going on. go-static-check raises this as a warning --- cmd/rtrdump/rtrdump.go | 2 +- lib/client.go | 2 +- prefixfile/prefixfile.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/rtrdump/rtrdump.go b/cmd/rtrdump/rtrdump.go index edb7520..c11ae07 100644 --- a/cmd/rtrdump/rtrdump.go +++ b/cmd/rtrdump/rtrdump.go @@ -164,7 +164,7 @@ func main() { serverKeyHash := ssh.FingerprintSHA256(key) if *ValidateSSH { if serverKeyHash != fmt.Sprintf("SHA256:%v", *SSHServerKey) { - return errors.New(fmt.Sprintf("Server key hash %v is different than expected key hash SHA256:%v", serverKeyHash, *SSHServerKey)) + return fmt.Errorf("server key hash %v is different than expected key hash SHA256:%v", serverKeyHash, *SSHServerKey) } } log.Infof("Connected to server %v via ssh. Fingerprint: %v", remote.String(), serverKeyHash) diff --git a/lib/client.go b/lib/client.go index 4bfa53d..05a5c6e 100644 --- a/lib/client.go +++ b/lib/client.go @@ -220,6 +220,6 @@ func (c *ClientSession) Start(addr string, connType int, configTLS *tls.Config, case TYPE_SSH: return c.StartSSH(addr, configSSH) default: - return errors.New(fmt.Sprintf("Unknown type %v", connType)) + return fmt.Errorf("unknown ClientSession type %v", connType) } } diff --git a/prefixfile/prefixfile.go b/prefixfile/prefixfile.go index a4bc3b1..eb50bb6 100644 --- a/prefixfile/prefixfile.go +++ b/prefixfile/prefixfile.go @@ -32,7 +32,7 @@ func (vrp *VRPJson) GetASN2() (uint32, error) { asnStr := strings.TrimLeft(asnc, "aAsS") asnInt, err := strconv.ParseUint(asnStr, 10, 32) if err != nil { - return 0, errors.New(fmt.Sprintf("Could not decode ASN string: %v", vrp.ASN)) + return 0, fmt.Errorf("could not decode ASN string: %v", vrp.ASN) } asn := uint32(asnInt) return asn, nil @@ -43,7 +43,7 @@ func (vrp *VRPJson) GetASN2() (uint32, error) { case int: return uint32(asnc), nil default: - return 0, errors.New(fmt.Sprintf("Could not decode ASN: %v", vrp.ASN)) + return 0, fmt.Errorf("could not decode ASN: %v", vrp.ASN) } } @@ -55,7 +55,7 @@ func (vrp *VRPJson) GetASN() uint32 { func (vrp *VRPJson) GetPrefix2() (*net.IPNet, error) { _, prefix, err := net.ParseCIDR(vrp.Prefix) if err != nil { - return nil, errors.New(fmt.Sprintf("Could not decode prefix: %v", vrp.Prefix)) + return nil, fmt.Errorf("could not decode prefix: %v", vrp.Prefix) } return prefix, nil }