diff --git a/.golangci.yaml b/.golangci.yaml index 23386c1..e35f26d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,3 +1,12 @@ linters: disable: - errcheck +linters-settings: + govet: + enable: + - fieldalignment +issues: + exclude-rules: + - path: _test\.go + linters: + - govet diff --git a/cert.go b/cert.go index ffa7bd9..0bae2eb 100644 --- a/cert.go +++ b/cert.go @@ -12,6 +12,8 @@ import ( ) // SelfSign options +// +//nolint:govet type SelfSign struct { CommonName string Hosts []string diff --git a/pkg/authn/authn.go b/pkg/authn/authn.go index 6ea7d93..fda2e0e 100644 --- a/pkg/authn/authn.go +++ b/pkg/authn/authn.go @@ -5,6 +5,8 @@ import ( ) // Authenticator middleware +// +//nolint:govet type Authenticator struct { Type string Authenticate func(*http.Request) error diff --git a/pkg/authn/basic.go b/pkg/authn/basic.go index 05406e5..c928a25 100644 --- a/pkg/authn/basic.go +++ b/pkg/authn/basic.go @@ -27,6 +27,8 @@ func Basic(username, password string) *BasicAuthenticator { } // BasicAuthenticator middleware +// +//nolint:govet type BasicAuthenticator struct { Realm string Authenticate func(r *http.Request, username, password string) error diff --git a/pkg/authn/forward.go b/pkg/authn/forward.go index a8b9c99..aee5c6b 100644 --- a/pkg/authn/forward.go +++ b/pkg/authn/forward.go @@ -126,10 +126,10 @@ func (m ForwardAuthenticator) ServeHandler(h http.Handler) http.Handler { } type ForwardServerError struct { + Response *http.Response + OriginError error StatusCode int IsTransportError bool - OriginError error - Response *http.Response } func (err *ForwardServerError) Error() string { diff --git a/pkg/block/block.go b/pkg/block/block.go index 3631b52..09c3047 100644 --- a/pkg/block/block.go +++ b/pkg/block/block.go @@ -15,9 +15,8 @@ func New(match func(r *http.Request) bool) *Block { // Block is middleware block type Block struct { - ms parapet.Middlewares - Match func(r *http.Request) bool + ms parapet.Middlewares } // Use uses middleware diff --git a/pkg/body/limit.go b/pkg/body/limit.go index bf76439..f980436 100644 --- a/pkg/body/limit.go +++ b/pkg/body/limit.go @@ -12,6 +12,8 @@ func LimitRequest(size int64) *RequestLimiter { } // RequestLimiter limits request body size +// +//nolint:govet type RequestLimiter struct { Size int64 LimitedHandler http.Handler diff --git a/pkg/compress/compress.go b/pkg/compress/compress.go index 519f7c0..73f9608 100644 --- a/pkg/compress/compress.go +++ b/pkg/compress/compress.go @@ -13,6 +13,8 @@ import ( ) // Compress is the compress middleware +// +//nolint:govet type Compress struct { New func() Compressor Encoding string // http Accept-Encoding, Content-Encoding value @@ -93,12 +95,13 @@ type Compressor interface { type compressWriter struct { http.ResponseWriter + pool *sync.Pool + types map[string]struct{} encoder Compressor encoding string - types map[string]struct{} - wroteHeader bool minLength int + wroteHeader bool } func (w *compressWriter) init() { diff --git a/pkg/cors/cors.go b/pkg/cors/cors.go index bcb0323..576a961 100644 --- a/pkg/cors/cors.go +++ b/pkg/cors/cors.go @@ -31,13 +31,13 @@ func AllowOrigins(origins ...string) AllowOriginFunc { // CORS middleware type CORS struct { - AllowAllOrigins bool AllowOrigins AllowOriginFunc AllowMethods []string AllowHeaders []string - AllowCredentials bool ExposeHeaders []string MaxAge time.Duration + AllowAllOrigins bool + AllowCredentials bool } // ServeHandler implements middleware interface diff --git a/pkg/fileserver/fileserver.go b/pkg/fileserver/fileserver.go index a54dcd1..8b97ed9 100644 --- a/pkg/fileserver/fileserver.go +++ b/pkg/fileserver/fileserver.go @@ -57,10 +57,11 @@ func (fs *fileSystem) Open(name string) (http.File, error) { type responseWriter struct { http.ResponseWriter - wroteHeader bool + header http.Header - noop bool notFound func() + wroteHeader bool + noop bool } func (w *responseWriter) Header() http.Header { diff --git a/pkg/gcs/gcs.go b/pkg/gcs/gcs.go index 5fbe670..50134bc 100644 --- a/pkg/gcs/gcs.go +++ b/pkg/gcs/gcs.go @@ -24,6 +24,8 @@ func New(client *storage.Client, bucket string, basePath string) *GCS { } // GCS proxies request to google cloud storage +// +//nolint:govet type GCS struct { Client *storage.Client Bucket string diff --git a/pkg/h2push/preload.go b/pkg/h2push/preload.go index c981693..f4d73fe 100644 --- a/pkg/h2push/preload.go +++ b/pkg/h2push/preload.go @@ -37,8 +37,8 @@ func (m PreloadPusher) ServeHandler(h http.Handler) http.Handler { type preloadPusherRW struct { http.ResponseWriter - wroteHeader bool header http.Header + wroteHeader bool } func (w *preloadPusherRW) Header() http.Header { diff --git a/pkg/headers/intercept.go b/pkg/headers/intercept.go index 09a79e6..ebdf2cb 100644 --- a/pkg/headers/intercept.go +++ b/pkg/headers/intercept.go @@ -68,10 +68,11 @@ func (m ResponseInterceptor) ServeHandler(h http.Handler) http.Handler { type interceptRW struct { http.ResponseWriter + + f ResponseInterceptFunc + status int wroteHeader bool intercepted bool - status int - f ResponseInterceptFunc } func (w *interceptRW) intercept() { diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 363261e..77f613f 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -94,10 +94,11 @@ func (m Logger) ServeHandler(h http.Handler) http.Handler { type responseWriter struct { http.ResponseWriter - wroteHeader bool + wroteHeaderAt time.Time - statusCode int length int64 + statusCode int + wroteHeader bool } func (w *responseWriter) WriteHeader(statusCode int) { diff --git a/pkg/logger/record.go b/pkg/logger/record.go index f3aef39..4b2f32c 100644 --- a/pkg/logger/record.go +++ b/pkg/logger/record.go @@ -9,9 +9,9 @@ import ( type ctxKeyRecord struct{} type record struct { + data map[string]interface{} mu sync.RWMutex disable bool - data map[string]interface{} } func newRecord() *record { diff --git a/pkg/prom/connections.go b/pkg/prom/connections.go index ecdd505..97a18f5 100644 --- a/pkg/prom/connections.go +++ b/pkg/prom/connections.go @@ -10,6 +10,7 @@ import ( "github.com/moonrhythm/parapet" ) +//nolint:govet type connections struct { once sync.Once vec *prometheus.GaugeVec diff --git a/pkg/prom/networks.go b/pkg/prom/networks.go index 6c3a3f9..650f4ca 100644 --- a/pkg/prom/networks.go +++ b/pkg/prom/networks.go @@ -9,6 +9,7 @@ import ( "github.com/moonrhythm/parapet" ) +//nolint:govet type networks struct { once sync.Once requests prometheus.Counter diff --git a/pkg/prom/requests.go b/pkg/prom/requests.go index 532c7c6..70d18fb 100644 --- a/pkg/prom/requests.go +++ b/pkg/prom/requests.go @@ -12,6 +12,7 @@ import ( "github.com/moonrhythm/parapet" ) +//nolint:govet type requests struct { once sync.Once vec *prometheus.CounterVec diff --git a/pkg/ratelimit/concurrent.go b/pkg/ratelimit/concurrent.go index 5f57370..5237c9c 100644 --- a/pkg/ratelimit/concurrent.go +++ b/pkg/ratelimit/concurrent.go @@ -15,6 +15,8 @@ func Concurrent(capacity int) *RateLimiter { // ConcurrentStrategy implements Strategy // that allow only max concurrent requests at a time // other requests will drop +// +//nolint:govet type ConcurrentStrategy struct { mu sync.Mutex storage map[string]int diff --git a/pkg/ratelimit/concurrentqueue.go b/pkg/ratelimit/concurrentqueue.go index 52a1eb5..66d17c9 100644 --- a/pkg/ratelimit/concurrentqueue.go +++ b/pkg/ratelimit/concurrentqueue.go @@ -16,6 +16,8 @@ func ConcurrentQueue(capacity, size int) *RateLimiter { // ConcurrentQueueStrategy implements Strategy // that allow only max concurrent requests at a time // other requests will queue, until queue full then the request wil drop +// +//nolint:govet type ConcurrentQueueStrategy struct { mu sync.Mutex storage map[string]*concurrentQueueItem diff --git a/pkg/ratelimit/fixedwindow.go b/pkg/ratelimit/fixedwindow.go index ae45b40..f67b381 100644 --- a/pkg/ratelimit/fixedwindow.go +++ b/pkg/ratelimit/fixedwindow.go @@ -29,6 +29,8 @@ func FixedWindowPerHour(rate int) *RateLimiter { } // FixedWindowStrategy implements Strategy using fixed window algorithm +// +//nolint:govet type FixedWindowStrategy struct { mu sync.RWMutex lastWindow int64 diff --git a/pkg/ratelimit/leakybucket.go b/pkg/ratelimit/leakybucket.go index 6deb35d..4a2d599 100644 --- a/pkg/ratelimit/leakybucket.go +++ b/pkg/ratelimit/leakybucket.go @@ -14,6 +14,8 @@ func LeakyBucket(perRequest time.Duration, size int) *RateLimiter { } // LeakyBucketStrategy implements Strategy using leaky bucket algorithm +// +//nolint:govet type LeakyBucketStrategy struct { mu sync.RWMutex storage map[string]*leakyItem diff --git a/pkg/requestid/requestid.go b/pkg/requestid/requestid.go index 2514417..fd8be9d 100644 --- a/pkg/requestid/requestid.go +++ b/pkg/requestid/requestid.go @@ -9,9 +9,11 @@ import ( ) // RequestID middleware +// +//nolint:govet type RequestID struct { // TrustProxy trusts request id from request header - // sets to false to always generate new request id + // sets TrustProxy to false for always generate new request id TrustProxy bool // Header is the http header key diff --git a/pkg/stackdriver/trace.go b/pkg/stackdriver/trace.go index f7f4866..aed6e30 100644 --- a/pkg/stackdriver/trace.go +++ b/pkg/stackdriver/trace.go @@ -19,6 +19,8 @@ func NewTrace() *Trace { } // Trace middleware +// +//nolint:govet type Trace struct { ProjectID string Propagation propagation.HTTPFormat diff --git a/pkg/timeout/timeout.go b/pkg/timeout/timeout.go index 603735b..1caea89 100644 --- a/pkg/timeout/timeout.go +++ b/pkg/timeout/timeout.go @@ -16,8 +16,8 @@ func New(timeout time.Duration) *Timout { // Timout sets a write header timeout type Timout struct { - Timeout time.Duration TimeoutHandler http.Handler + Timeout time.Duration } // ServeHandler implements middleware interface @@ -69,10 +69,10 @@ func (m Timout) ServeHandler(h http.Handler) http.Handler { type timeoutRW struct { http.ResponseWriter - mu sync.Mutex + header http.Header done chan struct{} + mu sync.Mutex wroteHeader bool - header http.Header timeout bool } diff --git a/pkg/upstream/loadbalancer.go b/pkg/upstream/loadbalancer.go index 7bb301d..efebf92 100644 --- a/pkg/upstream/loadbalancer.go +++ b/pkg/upstream/loadbalancer.go @@ -7,8 +7,8 @@ import ( // Target is the load balancer target type Target struct { - Host string Transport http.RoundTripper + Host string } // NewRoundRobinLoadBalancer creates new round-robin load balancer @@ -20,9 +20,8 @@ func NewRoundRobinLoadBalancer(targets []*Target) *RoundRobinLoadBalancer { // RoundRobinLoadBalancer strategy type RoundRobinLoadBalancer struct { - i uint32 - Targets []*Target + i uint32 } // RoundTrip sends a request to upstream server diff --git a/pkg/upstream/loadbalancer_test.go b/pkg/upstream/loadbalancer_test.go index d15afbe..87389dd 100644 --- a/pkg/upstream/loadbalancer_test.go +++ b/pkg/upstream/loadbalancer_test.go @@ -77,8 +77,8 @@ func TestRoundRobinLoadBalancer(t *testing.T) { } type fakeTransport struct { - called bool host string + called bool } func (tr *fakeTransport) RoundTrip(r *http.Request) (*http.Response, error) { diff --git a/pkg/upstream/transport.go b/pkg/upstream/transport.go index 42a6836..8eff296 100644 --- a/pkg/upstream/transport.go +++ b/pkg/upstream/transport.go @@ -21,6 +21,8 @@ const ( ) // H2CTransport type +// +//nolint:govet type H2CTransport struct { once sync.Once dialer *net.Dialer @@ -75,6 +77,8 @@ func (t *H2CTransport) RoundTrip(r *http.Request) (*http.Response, error) { } // HTTPTransport type +// +//nolint:govet type HTTPTransport struct { once sync.Once h *http.Transport @@ -126,6 +130,8 @@ func (t *HTTPTransport) RoundTrip(r *http.Request) (*http.Response, error) { } // HTTPSTransport type +// +//nolint:govet type HTTPSTransport struct { once sync.Once h *http.Transport @@ -185,6 +191,8 @@ func (t *HTTPSTransport) RoundTrip(r *http.Request) (*http.Response, error) { } // UnixTransport type +// +//nolint:govet type UnixTransport struct { once sync.Once h *http.Transport @@ -229,6 +237,8 @@ func (t *UnixTransport) RoundTrip(r *http.Request) (*http.Response, error) { } // Transport does RoundTrip dynamically from request's scheme +// +//nolint:govet type Transport struct { once sync.Once dialer *net.Dialer diff --git a/pkg/upstream/upstream.go b/pkg/upstream/upstream.go index d1465e8..460b84a 100644 --- a/pkg/upstream/upstream.go +++ b/pkg/upstream/upstream.go @@ -162,8 +162,8 @@ func SingleHost(host string, transport http.RoundTripper) *Upstream { } type singleHostTransport struct { - Host string Transport http.RoundTripper + Host string } func (l *singleHostTransport) RoundTrip(r *http.Request) (*http.Response, error) { diff --git a/proxy.go b/proxy.go index 7db9586..0750350 100644 --- a/proxy.go +++ b/proxy.go @@ -43,6 +43,7 @@ const ( headerXRealIP = "X-Real-Ip" ) +//nolint:govet type proxy struct { Trust func(r *http.Request) bool ComputeFullForwardedFor bool diff --git a/server.go b/server.go index 59e5565..6c2cd95 100644 --- a/server.go +++ b/server.go @@ -18,6 +18,8 @@ import ( ) // Server is the parapet server +// +//nolint:govet type Server struct { s http.Server once sync.Once