Skip to content

Commit

Permalink
Update golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
9seconds committed Jun 21, 2021
1 parent 0f71cd5 commit 52213e8
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v2
with:
version: v1.37.1
version: v1.41.1
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

GOLANGCI_LINT_VERSION := v1.37.1
GOLANGCI_LINT_VERSION := v1.41.1

GOBIN := $(ROOT_DIR)/.bin
GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)"
Expand Down
4 changes: 2 additions & 2 deletions auth/ip_whitelist_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (i *ipWhitelist) Authenticate(ctx *fasthttp.RequestCtx) (string, error) {
ip := ctx.RemoteIP()

if ip4 := ip.To4(); ip4 != nil {
addr := patricia.NewIPv4AddressFromBytes(ip4, 32)
addr := patricia.NewIPv4AddressFromBytes(ip4, 32) // nolint: gomnd

if ok, user, err := i.v4.FindDeepestTag(addr); ok && err == nil {
return user, nil
Expand All @@ -27,7 +27,7 @@ func (i *ipWhitelist) Authenticate(ctx *fasthttp.RequestCtx) (string, error) {
return "", ErrFailedAuth
}

addr := patricia.NewIPv6Address(ip, 128)
addr := patricia.NewIPv6Address(ip, 128) // nolint: gomnd

if ok, user, err := i.v6.FindDeepestTag(addr); ok && err == nil {
return user, nil
Expand Down
18 changes: 10 additions & 8 deletions ca/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (w *worker) Run() {
var conf *tls.Config

if cert := w.cache.Get(req.host); cert != nil {
conf = cert.(*tls.Config)
conf, _ = cert.(*tls.Config)
} else {
conf = w.process(req.host)
w.cache.Add(req.host, conf)
Expand All @@ -79,11 +79,13 @@ func (w *worker) process(host string) *tls.Config {
now := time.Now()

template := x509.Certificate{
SerialNumber: &big.Int{},
Issuer: w.ca.Leaf.Subject,
Subject: pkix.Name{},
NotBefore: now.AddDate(0, 0, -1), // 1 day before
NotAfter: now.AddDate(0, 3, 0), // 3 months after
SerialNumber: &big.Int{},
Issuer: w.ca.Leaf.Subject,
Subject: pkix.Name{},
// 1 day before
NotBefore: now.AddDate(0, 0, -1),
// 3 months after
NotAfter: now.AddDate(0, 3, 0), // nolint: gomnd
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
Expand All @@ -96,8 +98,8 @@ func (w *worker) process(host string) *tls.Config {
template.Subject.CommonName = host
}

randBytes := make([]byte, 64)
rand.Read(randBytes) // nolint: errcheck
randBytes := make([]byte, 64) // nolint: gomnd
rand.Read(randBytes) // nolint: errcheck
template.SerialNumber.SetBytes(randBytes)

certPriv, err := rsa.GenerateKey(rand.Reader, RSAKeyLength)
Expand Down
2 changes: 1 addition & 1 deletion cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func New(size int, ttl time.Duration, callback EvictCallback) Interface {
BufferItems: 64, // nolint: gomnd
Metrics: false,
OnEvict: func(_, _ uint64, value interface{}, _ int64) {
vv := value.(*cacheItem)
vv, _ := value.(*cacheItem)
callback(vv.key, vv.value)
},
}
Expand Down
2 changes: 1 addition & 1 deletion conns/unread_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (u *UnreadConn) Read(p []byte) (int, error) {
u.mutex.RLock()
defer u.mutex.RUnlock()

return u.reader.Read(p)
return u.reader.Read(p) // nolint: wrapcheck
}

// Unread transitions UnreadConn into 'unreading' state.
Expand Down
2 changes: 1 addition & 1 deletion dialers/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (h *httpProxy) PatchHTTPRequest(req *fasthttp.Request) {
}

func (h *httpProxy) acquireBufioReader(rd io.Reader) *bufio.Reader {
rv := h.bufioReaderPool.Get().(*bufio.Reader)
rv, _ := h.bufioReaderPool.Get().(*bufio.Reader)

rv.Reset(rd)

Expand Down
4 changes: 2 additions & 2 deletions dialers/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type socksProxy struct {
}

func (s *socksProxy) Dial(ctx context.Context, host, port string) (net.Conn, error) {
return s.proxy.DialContext(ctx, "tcp", net.JoinHostPort(host, port))
return s.proxy.DialContext(ctx, "tcp", net.JoinHostPort(host, port)) // nolint: wrapcheck
}

func (s *socksProxy) UpgradeToTLS(ctx context.Context, conn net.Conn, host, port string) (net.Conn, error) {
Expand All @@ -29,7 +29,7 @@ func (s *socksProxy) PatchHTTPRequest(req *fasthttp.Request) {
// NewSocks5 returns a dialer which can connect to SOCKS5 proxies. It
// uses a base dialer under the hood.
func NewSocks5(opt Opts, proxyAuth ProxyAuth) (Dialer, error) {
baseDialer := NewBase(opt).(*base)
baseDialer, _ := NewBase(opt).(*base)

var auth *proxy.Auth

Expand Down
2 changes: 1 addition & 1 deletion dialers/std_dialer_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s StdDialerWrapper) DialContext(ctx context.Context, network, address stri
return nil, fmt.Errorf("incorrect address: %w", err)
}

return s.Dialer.Dial(ctx, host, port)
return s.Dialer.Dial(ctx, host, port) // nolint: wrapcheck
}

// Dial is to conform Dial method of net.Dialer.
Expand Down
4 changes: 2 additions & 2 deletions dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type DNS struct {
// Lookup to conform Interface.
func (d *DNS) Lookup(ctx context.Context, hostname string) (hosts []string, err error) {
if hh := d.cache.Get(hostname); hh != nil {
hosts = hh.([]string)
hosts, _ = hh.([]string)
} else {
hosts, err = d.doLookup(ctx, hostname)

Expand All @@ -35,7 +35,7 @@ func (d *DNS) Lookup(ctx context.Context, hostname string) (hosts []string, err

func (d *DNS) doLookup(ctx context.Context, hostname string) ([]string, error) {
if net.ParseIP(hostname) == nil {
return d.resolver.LookupHost(ctx, hostname)
return d.resolver.LookupHost(ctx, hostname) // nolint: wrapcheck
}

addrs, err := d.resolver.LookupIPAddr(ctx, hostname)
Expand Down
2 changes: 1 addition & 1 deletion errors/error_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type errorJSON struct {
type errorJSONStackEntry struct {
Code string `json:"code"`
Message string `json:"message"`
StatusCode int `json:"status_code"`
StatusCode int `json:"status_code"` // nolint: tagliatelle
}

func writeErrorAsJSON(err *Error, writer io.Writer) {
Expand Down
2 changes: 1 addition & 1 deletion headers/bufio_reader_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var poolBufioReader = sync.Pool{
}

func acquireBufioReader(rd io.Reader) *bufio.Reader {
reader := poolBufioReader.Get().(*bufio.Reader)
reader, _ := poolBufioReader.Get().(*bufio.Reader)

reader.Reset(rd)

Expand Down
2 changes: 1 addition & 1 deletion headers/bytes_reader_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var poolBytesReader = sync.Pool{
}

func acquireBytesReader(data []byte) *bytes.Reader {
rd := poolBytesReader.Get().(*bytes.Reader)
rd, _ := poolBytesReader.Get().(*bytes.Reader)

rd.Reset(data)

Expand Down
2 changes: 1 addition & 1 deletion http/buffered_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var poolBufioReader = sync.Pool{
}

func acquireBufioReader(rd io.Reader) *bufio.Reader {
reader := poolBufioReader.Get().(*bufio.Reader)
reader, _ := poolBufioReader.Get().(*bufio.Reader)

reader.Reset(rd)

Expand Down
2 changes: 1 addition & 1 deletion layers/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (c *Context) Done() <-chan struct{} {

// Err conforms a context.Context interface.
func (c *Context) Err() error {
return c.ctx.Err()
return c.ctx.Err() // nolint: wrapcheck
}

// Value conforms a context.Context interface.
Expand Down
10 changes: 4 additions & 6 deletions layers/layer_filter_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (f *filterSubnetsLayer) OnRequest(ctx *Context) error {
resolved, err := dns.Default.Lookup(ctx, host)
if err != nil {
// pass unresolved name, delegate it to executor.
return nil
return nil // nolint: nilerr
}

for _, v := range resolved {
Expand All @@ -39,17 +39,15 @@ func (f *filterSubnetsLayer) OnRequest(ctx *Context) error {
}

func (f *filterSubnetsLayer) filterIP(ip net.IP) bool {
ip4 := ip.To4()

if ip4 != nil {
if ip4 := ip.To4(); ip4 != nil {
return f.filterIPv4(ip4)
}

return f.filterIPv6(ip)
}

func (f *filterSubnetsLayer) filterIPv4(addr net.IP) bool {
ip := patricia.NewIPv4AddressFromBytes(addr, 32)
ip := patricia.NewIPv4AddressFromBytes(addr, 32) // nolint: gomnd

if ok, _, err := f.v4.FindDeepestTag(ip); ok && err == nil {
return true
Expand All @@ -59,7 +57,7 @@ func (f *filterSubnetsLayer) filterIPv4(addr net.IP) bool {
}

func (f *filterSubnetsLayer) filterIPv6(addr net.IP) bool {
ip := patricia.NewIPv6Address(addr, 128)
ip := patricia.NewIPv6Address(addr, 128) // nolint: gomnd

if ok, _, err := f.v6.FindDeepestTag(ip); ok && err == nil {
return true
Expand Down
8 changes: 4 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ type Server struct {

// Serve starts to serve on given net.Listener instance.
func (s *Server) Serve(ln net.Listener) error {
return s.server.Serve(ln)
return s.server.Serve(ln) // nolint: wrapcheck
}

// Close stops server.
func (s *Server) Close() error {
s.ctxCancel()

return s.server.Shutdown()
return s.server.Shutdown() // nolint: wrapcheck
}

func (s *Server) entrypoint(ctx *fasthttp.RequestCtx) {
Expand Down Expand Up @@ -134,7 +134,7 @@ func (s *Server) upgradeToTLS(requestType events.RequestType, user, address stri
uConn.Seal()
}

srv := s.serverPool.Get().(*fasthttp.Server)
srv, _ := s.serverPool.Get().(*fasthttp.Server)
defer s.serverPool.Put(srv)

needToClose := true
Expand Down Expand Up @@ -318,7 +318,7 @@ func NewServer(ctx context.Context, opts ServerOpts) (*Server, error) { // nolin
},
},
}
srv.server = srv.serverPool.Get().(*fasthttp.Server)
srv.server, _ = srv.serverPool.Get().(*fasthttp.Server)
srv.server.Handler = srv.entrypoint

go func() {
Expand Down
4 changes: 2 additions & 2 deletions upgrades/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var poolTCP = sync.Pool{

// AcquireTCP returns a new TCP upgrader from the pool.
func AcquireTCP(reactor TCPReactor) Interface {
rv := poolTCP.Get().(*tcpInterface)
rv, _ := poolTCP.Get().(*tcpInterface)

rv.reactor = reactor

Expand All @@ -122,7 +122,7 @@ func AcquireTCP(reactor TCPReactor) Interface {

// ReleaseTCP returns TCP upgrader back to the object pool.
func ReleaseTCP(up Interface) {
value := up.(*tcpInterface)
value, _ := up.(*tcpInterface)
value.reactor = nil

poolTCP.Put(value)
Expand Down
4 changes: 2 additions & 2 deletions upgrades/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var poolWebsocket = sync.Pool{

// AcquireWebsocket returns a new Websocket upgrader from the pool.
func AcquireWebsocket(reactor WebsocketReactor) Interface {
rv := poolWebsocket.Get().(*websocketInterface)
rv, _ := poolWebsocket.Get().(*websocketInterface)

rv.reactor = reactor

Expand All @@ -133,7 +133,7 @@ func AcquireWebsocket(reactor WebsocketReactor) Interface {

// ReleaseWebsocket returns Websocket back to the object pool.
func ReleaseWebsocket(up Interface) {
value := up.(*websocketInterface)
value, _ := up.(*websocketInterface)
value.reactor = nil

poolWebsocket.Put(value)
Expand Down

0 comments on commit 52213e8

Please sign in to comment.