Skip to content

Enable govet fieldalignment linter #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ linters-settings:
- name: var-naming
gocyclo:
min-complexity: 15
govet:
enable:
- fieldalignment

linters:
enable:
Expand Down
10 changes: 5 additions & 5 deletions cmd/gateway/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ const (
type (
Validator func(*flag.FlagSet) error
ValidatorContext struct {
Key string
V Validator
Key string
}
)

func GatewayControllerParam(domain string) ValidatorContext {
name := "gateway-ctlr-name"
return ValidatorContext{
name,
func(flagset *flag.FlagSet) error {
Key: name,
V: func(flagset *flag.FlagSet) error {
param, err := flagset.GetString(name)
if err != nil {
return err
Expand Down Expand Up @@ -68,8 +68,8 @@ func validateControllerName(name string) error {
func GatewayClassParam() ValidatorContext {
name := "gatewayclass"
return ValidatorContext{
name,
func(flagset *flag.FlagSet) error {
Key: name,
V: func(flagset *flag.FlagSet) error {
param, err := flagset.GetString(name)
if err != nil {
return err
Expand Down
56 changes: 28 additions & 28 deletions cmd/gateway/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

func MockValidator(name string, called *int, succeed bool) ValidatorContext {
return ValidatorContext{
name,
func(_ *flag.FlagSet) error {
Key: name,
V: func(_ *flag.FlagSet) error {
*called++

if !succeed {
Expand Down Expand Up @@ -41,71 +41,71 @@ var _ = Describe("Main", func() {
It("should call all validators", func() {
var called int
table := []struct {
Contexts []ValidatorContext
ExpectedCalls int
Success bool
Contexts []ValidatorContext
}{
{
0,
true,
[]ValidatorContext{},
Contexts: []ValidatorContext{},
ExpectedCalls: 0,
Success: true,
},
{
0,
true,
[]ValidatorContext{
Contexts: []ValidatorContext{
MockValidator("no-flag-set", &called, true),
},
ExpectedCalls: 0,
Success: true,
},
{
1,
true,
[]ValidatorContext{
Contexts: []ValidatorContext{
MockValidator("validator-1", &called, true),
},
ExpectedCalls: 1,
Success: true,
},
{
1,
true,
[]ValidatorContext{
Contexts: []ValidatorContext{
MockValidator("no-flag-set", &called, true),
MockValidator("validator-1", &called, true),
},
ExpectedCalls: 1,
Success: true,
},
{
2,
true,
[]ValidatorContext{
Contexts: []ValidatorContext{
MockValidator("validator-1", &called, true),
MockValidator("validator-2", &called, true),
},
ExpectedCalls: 2,
Success: true,
},
{
3,
true,
[]ValidatorContext{
Contexts: []ValidatorContext{
MockValidator("validator-1", &called, true),
MockValidator("validator-2", &called, true),
MockValidator("validator-3", &called, true),
},
ExpectedCalls: 3,
Success: true,
},
{
3,
false,
[]ValidatorContext{
Contexts: []ValidatorContext{
MockValidator("validator-1", &called, false),
MockValidator("validator-2", &called, true),
MockValidator("validator-3", &called, true),
},
ExpectedCalls: 3,
Success: false,
},
{
3,
false,
[]ValidatorContext{
Contexts: []ValidatorContext{
MockValidator("validator-1", &called, true),
MockValidator("validator-2", &called, true),
MockValidator("validator-3", &called, false),
},
ExpectedCalls: 3,
Success: false,
},
}

Expand All @@ -120,9 +120,9 @@ var _ = Describe("Main", func() {

Describe("CLI argument validation", func() {
type testCase struct {
ValidatorContext ValidatorContext
Flag string
Value string
ValidatorContext ValidatorContext
ExpError bool
}

Expand Down
4 changes: 2 additions & 2 deletions internal/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type UpsertEvent struct {

// DeleteEvent representing deleting a resource.
type DeleteEvent struct {
// NamespacedName is the namespace & name of the deleted resource.
NamespacedName types.NamespacedName
// Type is the resource type. For example, if the event is for *v1beta1.HTTPRoute, pass &v1beta1.HTTPRoute{} as Type.
Type client.Object
// NamespacedName is the namespace & name of the deleted resource.
NamespacedName types.NamespacedName
}
2 changes: 1 addition & 1 deletion internal/events/first_eventbatch_preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ type EachListItemFunc func(obj runtime.Object, fn func(runtime.Object) error) er
// FirstEventBatchPreparerImpl is an implementation of FirstEventBatchPreparer.
type FirstEventBatchPreparerImpl struct {
reader Reader
eachListItem EachListItemFunc
objects []client.Object
objectLists []client.ObjectList
eachListItem EachListItemFunc
}

// NewFirstEventBatchPreparerImpl creates a new FirstEventBatchPreparerImpl.
Expand Down
4 changes: 2 additions & 2 deletions internal/events/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ type EventHandlerConfig struct {
SecretMemoryManager state.SecretDiskMemoryManager
// Generator is the nginx config Generator.
Generator config.Generator
// Logger is the logger to be used by the EventHandler.
Logger logr.Logger
// NginxFileMgr is the file Manager for nginx.
NginxFileMgr file.Manager
// NginxRuntimeMgr manages nginx runtime.
NginxRuntimeMgr runtime.Manager
// StatusUpdater updates statuses on Kubernetes resources.
StatusUpdater status.Updater
// Logger is the logger to be used by the EventHandler.
Logger logr.Logger
}

// EventHandlerImpl implements EventHandler.
Expand Down
7 changes: 3 additions & 4 deletions internal/events/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ import (
// FIXME(pleshakov): better document the side effects and how to prevent and mitigate them.
// So when the EventLoop have 100 saved events, it is better to process them at once rather than one by one.
type EventLoop struct {
eventCh <-chan interface{}
logger logr.Logger
handler EventHandler

handler EventHandler
preparer FirstEventBatchPreparer
eventCh <-chan interface{}
logger logr.Logger
}

// NewEventLoop creates a new EventLoop.
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/controllers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestRegisterController(t *testing.T) {
tests := []struct {
fakes fakes
expectedErr error
expectedMgrAddCallCount int
msg string
expectedMgrAddCallCount int
}{
{
fakes: getDefaultFakes(),
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/predicate/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type ServicePortsChangedPredicate struct {

// ports contains the ports that the Gateway cares about.
type ports struct {
servicePort int32
targetPort intstr.IntOrString
servicePort int32
}

// Update implements default UpdateEvent filter for validating Service port changes.
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/predicate/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

func TestServicePortsChangedPredicate_Update(t *testing.T) {
testcases := []struct {
msg string
objectOld client.Object
objectNew client.Object
msg string
expUpdate bool
}{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/nginx/config/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Location struct {

// Return represents an HTTP return.
type Return struct {
Code StatusCode
URL string
Code StatusCode
}

// SSL holds all SSL related configuration.
Expand Down
8 changes: 4 additions & 4 deletions internal/nginx/config/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ func createReturnValForRedirectFilter(filter *v1beta1.HTTPRequestRedirectFilter,
// The NJS httpmatches module will lookup this variable on the request object and compare the request against the Method, Headers, and QueryParams contained in httpMatch.
// If the request satisfies the httpMatch, the request will be internally redirected to the location RedirectPath by NGINX.
type httpMatch struct {
// Any represents a match with no match conditions.
Any bool `json:"any,omitempty"`
// Method is the HTTPMethod of the HTTPRouteMatch.
Method v1beta1.HTTPMethod `json:"method,omitempty"`
// RedirectPath is the path to redirect the request to if the request satisfies the match conditions.
RedirectPath string `json:"redirectPath,omitempty"`
// Headers is a list of HTTPHeaders name value pairs with the format "{name}:{value}".
Headers []string `json:"headers,omitempty"`
// QueryParams is a list of HTTPQueryParams name value pairs with the format "{name}={value}".
QueryParams []string `json:"params,omitempty"`
// RedirectPath is the path to redirect the request to if the request satisfies the match conditions.
RedirectPath string `json:"redirectPath,omitempty"`
// Any represents a match with no match conditions.
Any bool `json:"any,omitempty"`
}

func createHTTPMatch(match v1beta1.HTTPRouteMatch, redirectPath string) httpMatch {
Expand Down
6 changes: 3 additions & 3 deletions internal/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func TestExecuteServers(t *testing.T) {

func TestExecuteForDefaultServers(t *testing.T) {
testcases := []struct {
msg string
conf state.Configuration
httpDefault bool
sslDefault bool
msg string
}{
{
conf: state.Configuration{},
Expand Down Expand Up @@ -624,8 +624,8 @@ func TestCreateHTTPMatch(t *testing.T) {

tests := []struct {
match v1beta1.HTTPRouteMatch
expected httpMatch
msg string
expected httpMatch
}{
{
match: v1beta1.HTTPRouteMatch{
Expand Down Expand Up @@ -781,8 +781,8 @@ func TestCreateHeaderKeyValString(t *testing.T) {
func TestIsPathOnlyMatch(t *testing.T) {
tests := []struct {
match v1beta1.HTTPRouteMatch
expected bool
msg string
expected bool
}{
{
match: v1beta1.HTTPRouteMatch{
Expand Down
4 changes: 2 additions & 2 deletions internal/nginx/config/split_clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ func TestCreateSplitClientDistributions(t *testing.T) {
func TestGetSplitClientValue(t *testing.T) {
tests := []struct {
msg string
backend state.BackendRef
expValue string
backend state.BackendRef
}{
{
msg: "valid backend",
Expand Down Expand Up @@ -598,8 +598,8 @@ func TestBackendGroupNeedsSplit(t *testing.T) {
func TestBackendGroupName(t *testing.T) {
tests := []struct {
msg string
backends []state.BackendRef
expName string
backends []state.BackendRef
}{
{
msg: "empty backends",
Expand Down
2 changes: 1 addition & 1 deletion internal/nginx/config/upstreams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ func TestCreateUpstreams(t *testing.T) {

func TestCreateUpstream(t *testing.T) {
tests := []struct {
msg string
stateUpstream state.Upstream
expectedUpstream http.Upstream
msg string
}{
{
stateUpstream: state.Upstream{
Expand Down
2 changes: 1 addition & 1 deletion internal/nginx/runtime/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func TestFindMainProcess(t *testing.T) {

tests := []struct {
readFile readFileFunc
msg string
expected int
expectError bool
msg string
}{
{
readFile: readFileFuncGen([]byte("1\n")),
Expand Down
8 changes: 4 additions & 4 deletions internal/state/backend_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (

// BackendGroup represents a group of backends for a rule in an HTTPRoute.
type BackendGroup struct {
Errors []string
Source types.NamespacedName
RuleIdx int
Errors []string
Backends []BackendRef
RuleIdx int
}

// BackendRef is an internal representation of a backendRef in an HTTPRoute.
type BackendRef struct {
Name string
Svc *v1.Service
Name string
Port int32
Valid bool
Weight int32
Valid bool
}

// GroupName returns the name of the backend group.
Expand Down
4 changes: 2 additions & 2 deletions internal/state/backend_refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func getModifiedRef(mod func(ref v1beta1.BackendRef) v1beta1.BackendRef) v1beta1

func TestValidateBackendRef(t *testing.T) {
tests := []struct {
msg string
ref v1beta1.BackendRef
msg string
expErr bool
}{
{
Expand Down Expand Up @@ -107,9 +107,9 @@ func TestGetServiceAndPortFromRef(t *testing.T) {
}

tests := []struct {
msg string
ref v1beta1.BackendRef
expService *v1.Service
msg string
expPort int32
expErr bool
}{
Expand Down
Loading