From 52edbbdc180dd5e5ee060d7be64355b09d574f1c Mon Sep 17 00:00:00 2001 From: Adam Chalkley Date: Thu, 8 Apr 2021 10:51:23 -0500 Subject: [PATCH] Fix govet:fieldalignment linting errors Change field order of `Config` struct to reduce allocation requirements and pass `fieldalignment` linting check. refs GH-127 --- .golangci.yml | 27 ++++++++++++++-------- cmd/bounce/decode-json-body.go | 2 +- cmd/bounce/notify.go | 15 ++++++------ config/config.go | 42 +++++++++++++++++----------------- routes/routes.go | 2 +- 5 files changed, 48 insertions(+), 40 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 121b459c..7f6eb4d0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,18 +16,25 @@ issues: linters: enable: + - depguard - dogsled + - dupl + - goconst + - gocritic + - gofmt - goimports + - golint - gosec - - stylecheck - - goconst - - depguard - - prealloc - misspell - - maligned - - dupl + - prealloc + - exportloopref + - stylecheck - unconvert - - gofmt - - golint - - gocritic - - scopelint + + disable: + - maligned + +linters-settings: + govet: + enable: + - fieldalignment diff --git a/cmd/bounce/decode-json-body.go b/cmd/bounce/decode-json-body.go index b54554b1..a4bcb8b6 100644 --- a/cmd/bounce/decode-json-body.go +++ b/cmd/bounce/decode-json-body.go @@ -22,8 +22,8 @@ import ( ) type malformedRequest struct { - status int msg string + status int } // malformedRequest wraps errors from decoding JSON request bodies diff --git a/cmd/bounce/notify.go b/cmd/bounce/notify.go index ebc714c9..a7346ded 100644 --- a/cmd/bounce/notify.go +++ b/cmd/bounce/notify.go @@ -15,14 +15,14 @@ import ( // error or success conditions type NotifyResult struct { - // Val is the non-error condition message to return from a notification - // operation - Val string - // Err is the error condition message to return from a notification // operation Err error + // Val is the non-error condition message to return from a notification + // operation + Val string + // Success indicates whether the notification attempt succeeded or if it // failed for one reason or another (remote API, timeout, cancellation, // etc) @@ -32,13 +32,14 @@ type NotifyResult struct { // NotifyQueue represents a channel used to queue input data and responses // between the main application, the notifications manager and "notifiers". type NotifyQueue struct { - // The name of a queue. This is intended for display in log messages or - // other output to identify queues with pending items. - Name string // Channel is a channel used to transport input data and responses. Channel interface{} + // The name of a queue. This is intended for display in log messages or + // other output to identify queues with pending items. + Name string + // Count is the number of items currently in the queue Count int diff --git a/config/config.go b/config/config.go index de80cc3e..4014b95d 100644 --- a/config/config.go +++ b/config/config.go @@ -250,31 +250,10 @@ func Usage(flagSet *flag.FlagSet) func() { // command-line flags type Config struct { - // Retries is the number of attempts that this application will make - // to deliver messages before giving up. - Retries int - - // RetriesDelay is the number of seconds to wait between retry attempts. - RetriesDelay int - - // LocalTCPPort is the TCP port that this application should listen on for - // incoming requests - LocalTCPPort int - // LocalIPAddress is the IP Address that this application should listen on // for incoming requests LocalIPAddress string - // ColorizedJSON indicates whether JSON output should be colorized. - // Coloring the output could aid in in quick visual evaluation of incoming - // payloads - ColorizedJSON bool - - // ColorizedJSONIndent controls how many spaces are used when indenting - // colorized JSON output. If ColorizedJSON is not enabled, this setting - // has no effect. - ColorizedJSONIndent int - // LogLevel is the chosen logging level LogLevel string @@ -295,6 +274,27 @@ type Config struct { // advance by adding/configuring a Webhook Connector in a Microsoft Teams // channel that you wish to submit messages to using this application. WebhookURL string + + // Retries is the number of attempts that this application will make + // to deliver messages before giving up. + Retries int + + // RetriesDelay is the number of seconds to wait between retry attempts. + RetriesDelay int + + // LocalTCPPort is the TCP port that this application should listen on for + // incoming requests + LocalTCPPort int + + // ColorizedJSONIndent controls how many spaces are used when indenting + // colorized JSON output. If ColorizedJSON is not enabled, this setting + // has no effect. + ColorizedJSONIndent int + + // ColorizedJSON indicates whether JSON output should be colorized. + // Coloring the output could aid in in quick visual evaluation of incoming + // payloads + ColorizedJSON bool } func (c *Config) String() string { diff --git a/routes/routes.go b/routes/routes.go index ecb7c81a..66695c82 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -17,10 +17,10 @@ import ( // API. type Route struct { Name string - AllowedMethods []string Pattern string Description string HandlerFunc http.HandlerFunc + AllowedMethods []string } // Routes is a collection of defined routes, intended for bulk registration