Skip to content

Commit

Permalink
Use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...))
Browse files Browse the repository at this point in the history
This fixes some lint output.
  • Loading branch information
cespare committed Feb 26, 2015
1 parent dc58428 commit 47b2d37
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
5 changes: 2 additions & 3 deletions apps/nsq_to_http/nsq_to_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"bytes"
"errors"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -139,7 +138,7 @@ func (p *PostPublisher) Publish(addr string, msg []byte) error {
resp.Body.Close()

if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return errors.New(fmt.Sprintf("got status code %d", resp.StatusCode))
return fmt.Errorf("got status code %d", resp.StatusCode)
}
return nil
}
Expand All @@ -156,7 +155,7 @@ func (p *GetPublisher) Publish(addr string, msg []byte) error {
resp.Body.Close()

if resp.StatusCode != 200 {
return errors.New(fmt.Sprintf("got status code %d", resp.StatusCode))
return fmt.Errorf("got status code %d", resp.StatusCode)
}
return nil
}
Expand Down
11 changes: 5 additions & 6 deletions nsqd/client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"compress/flate"
"crypto/tls"
"errors"
"fmt"
"net"
"sync"
Expand Down Expand Up @@ -408,7 +407,7 @@ func (c *clientV2) SetHeartbeatInterval(desiredInterval int) error {
desiredInterval <= int(c.ctx.nsqd.opts.MaxHeartbeatInterval/time.Millisecond):
c.HeartbeatInterval = time.Duration(desiredInterval) * time.Millisecond
default:
return errors.New(fmt.Sprintf("heartbeat interval (%d) is invalid", desiredInterval))
return fmt.Errorf("heartbeat interval (%d) is invalid", desiredInterval)
}

return nil
Expand All @@ -426,7 +425,7 @@ func (c *clientV2) SetOutputBufferSize(desiredSize int) error {
case desiredSize >= 64 && desiredSize <= int(c.ctx.nsqd.opts.MaxOutputBufferSize):
size = desiredSize
default:
return errors.New(fmt.Sprintf("output buffer size (%d) is invalid", desiredSize))
return fmt.Errorf("output buffer size (%d) is invalid", desiredSize)
}

if size > 0 {
Expand Down Expand Up @@ -456,15 +455,15 @@ func (c *clientV2) SetOutputBufferTimeout(desiredTimeout int) error {
desiredTimeout <= int(c.ctx.nsqd.opts.MaxOutputBufferTimeout/time.Millisecond):
c.OutputBufferTimeout = time.Duration(desiredTimeout) * time.Millisecond
default:
return errors.New(fmt.Sprintf("output buffer timeout (%d) is invalid", desiredTimeout))
return fmt.Errorf("output buffer timeout (%d) is invalid", desiredTimeout)
}

return nil
}

func (c *clientV2) SetSampleRate(sampleRate int32) error {
if sampleRate < 0 || sampleRate > 99 {
return errors.New(fmt.Sprintf("sample rate (%d) is invalid", sampleRate))
return fmt.Errorf("sample rate (%d) is invalid", sampleRate)
}
atomic.StoreInt32(&c.SampleRate, sampleRate)
return nil
Expand All @@ -481,7 +480,7 @@ func (c *clientV2) SetMsgTimeout(msgTimeout int) error {
msgTimeout <= int(c.ctx.nsqd.opts.MaxMsgTimeout/time.Millisecond):
c.MsgTimeout = time.Duration(msgTimeout) * time.Millisecond
default:
return errors.New(fmt.Sprintf("msg timeout (%d) is invalid", msgTimeout))
return fmt.Errorf("msg timeout (%d) is invalid", msgTimeout)
}

return nil
Expand Down
7 changes: 3 additions & 4 deletions nsqd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nsqd
import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -66,7 +65,7 @@ func (s *httpServer) debugRouter(w http.ResponseWriter, req *http.Request) error
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
return fmt.Errorf("404 %s", req.URL.Path)
}
return nil
}
Expand Down Expand Up @@ -117,7 +116,7 @@ func (s *httpServer) v1Router(w http.ResponseWriter, req *http.Request) error {
func() (interface{}, error) { return s.doPauseChannel(req) }))

default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
return fmt.Errorf("404 %s", req.URL.Path)
}
return nil
}
Expand Down Expand Up @@ -162,7 +161,7 @@ func (s *httpServer) deprecatedRouter(w http.ResponseWriter, req *http.Request)
util.NegotiateAPIResponseWrapper(w, req,
func() (interface{}, error) { return s.doCreateChannel(req) })
default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
return fmt.Errorf("404 %s", req.URL.Path)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions nsqd/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nsqd
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -67,7 +66,7 @@ func decodeMessage(b []byte) (*Message, error) {
var msg Message

if len(b) < 26 {
return nil, errors.New(fmt.Sprintf("invalid message buffer size (%d)", len(b)))
return nil, fmt.Errorf("invalid message buffer size (%d)", len(b))
}

msg.Timestamp = int64(binary.BigEndian.Uint64(b[:8]))
Expand Down
7 changes: 3 additions & 4 deletions nsqlookupd/http.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nsqlookupd

import (
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -55,7 +54,7 @@ func (s *httpServer) debugRouter(w http.ResponseWriter, req *http.Request) error
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
return fmt.Errorf("404 %s", req.URL.Path)
}
return nil
}
Expand Down Expand Up @@ -96,7 +95,7 @@ func (s *httpServer) v1Router(w http.ResponseWriter, req *http.Request) error {
func() (interface{}, error) { return s.doDeleteChannel(req) }))

default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
return fmt.Errorf("404 %s", req.URL.Path)
}
return nil
}
Expand All @@ -122,7 +121,7 @@ func (s *httpServer) deprecatedRouter(w http.ResponseWriter, req *http.Request)
util.NegotiateAPIResponseWrapper(w, req,
func() (interface{}, error) { return s.doCreateChannel(req) })
default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
return fmt.Errorf("404 %s", req.URL.Path)
}
return nil
}
Expand Down

0 comments on commit 47b2d37

Please sign in to comment.