Skip to content

Commit

Permalink
ci: add fieldalignment
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed May 10, 2023
1 parent cc82f6a commit ecfa482
Show file tree
Hide file tree
Showing 31 changed files with 76 additions and 25 deletions.
9 changes: 9 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
linters:
disable:
- errcheck
linters-settings:
govet:
enable:
- fieldalignment
issues:
exclude-rules:
- path: _test\.go
linters:
- govet
2 changes: 2 additions & 0 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

// SelfSign options
//
//nolint:govet
type SelfSign struct {
CommonName string
Hosts []string
Expand Down
2 changes: 2 additions & 0 deletions pkg/authn/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
)

// Authenticator middleware
//
//nolint:govet
type Authenticator struct {
Type string
Authenticate func(*http.Request) error
Expand Down
2 changes: 2 additions & 0 deletions pkg/authn/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/authn/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/body/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ func LimitRequest(size int64) *RequestLimiter {
}

// RequestLimiter limits request body size
//
//nolint:govet
type RequestLimiter struct {
Size int64
LimitedHandler http.Handler
Expand Down
7 changes: 5 additions & 2 deletions pkg/compress/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/fileserver/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/h2push/preload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/headers/intercept.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/prom/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/moonrhythm/parapet"
)

//nolint:govet
type connections struct {
once sync.Once
vec *prometheus.GaugeVec
Expand Down
1 change: 1 addition & 0 deletions pkg/prom/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/moonrhythm/parapet"
)

//nolint:govet
type networks struct {
once sync.Once
requests prometheus.Counter
Expand Down
1 change: 1 addition & 0 deletions pkg/prom/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/moonrhythm/parapet"
)

//nolint:govet
type requests struct {
once sync.Once
vec *prometheus.CounterVec
Expand Down
2 changes: 2 additions & 0 deletions pkg/ratelimit/concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/ratelimit/concurrentqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/ratelimit/fixedwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/ratelimit/leakybucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/requestid/requestid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/stackdriver/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func NewTrace() *Trace {
}

// Trace middleware
//
//nolint:govet
type Trace struct {
ProjectID string
Propagation propagation.HTTPFormat
Expand Down
6 changes: 3 additions & 3 deletions pkg/timeout/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/upstream/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/upstream/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/upstream/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
)

// H2CTransport type
//
//nolint:govet
type H2CTransport struct {
once sync.Once
dialer *net.Dialer
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
headerXRealIP = "X-Real-Ip"
)

//nolint:govet
type proxy struct {
Trust func(r *http.Request) bool
ComputeFullForwardedFor bool
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
)

// Server is the parapet server
//
//nolint:govet
type Server struct {
s http.Server
once sync.Once
Expand Down

0 comments on commit ecfa482

Please sign in to comment.