Skip to content

Commit aebbdeb

Browse files
authored
Enable govet fieldalignment linter (#284)
Enable fieldalignment and fix errors
1 parent 32ba4f5 commit aebbdeb

29 files changed

+105
-102
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ linters-settings:
3232
- name: var-naming
3333
gocyclo:
3434
min-complexity: 15
35+
govet:
36+
enable:
37+
- fieldalignment
3538

3639
linters:
3740
enable:

cmd/gateway/setup.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ const (
2222
type (
2323
Validator func(*flag.FlagSet) error
2424
ValidatorContext struct {
25-
Key string
2625
V Validator
26+
Key string
2727
}
2828
)
2929

3030
func GatewayControllerParam(domain string) ValidatorContext {
3131
name := "gateway-ctlr-name"
3232
return ValidatorContext{
33-
name,
34-
func(flagset *flag.FlagSet) error {
33+
Key: name,
34+
V: func(flagset *flag.FlagSet) error {
3535
param, err := flagset.GetString(name)
3636
if err != nil {
3737
return err
@@ -68,8 +68,8 @@ func validateControllerName(name string) error {
6868
func GatewayClassParam() ValidatorContext {
6969
name := "gatewayclass"
7070
return ValidatorContext{
71-
name,
72-
func(flagset *flag.FlagSet) error {
71+
Key: name,
72+
V: func(flagset *flag.FlagSet) error {
7373
param, err := flagset.GetString(name)
7474
if err != nil {
7575
return err

cmd/gateway/setup_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
func MockValidator(name string, called *int, succeed bool) ValidatorContext {
1414
return ValidatorContext{
15-
name,
16-
func(_ *flag.FlagSet) error {
15+
Key: name,
16+
V: func(_ *flag.FlagSet) error {
1717
*called++
1818

1919
if !succeed {
@@ -41,71 +41,71 @@ var _ = Describe("Main", func() {
4141
It("should call all validators", func() {
4242
var called int
4343
table := []struct {
44+
Contexts []ValidatorContext
4445
ExpectedCalls int
4546
Success bool
46-
Contexts []ValidatorContext
4747
}{
4848
{
49-
0,
50-
true,
51-
[]ValidatorContext{},
49+
Contexts: []ValidatorContext{},
50+
ExpectedCalls: 0,
51+
Success: true,
5252
},
5353
{
54-
0,
55-
true,
56-
[]ValidatorContext{
54+
Contexts: []ValidatorContext{
5755
MockValidator("no-flag-set", &called, true),
5856
},
57+
ExpectedCalls: 0,
58+
Success: true,
5959
},
6060
{
61-
1,
62-
true,
63-
[]ValidatorContext{
61+
Contexts: []ValidatorContext{
6462
MockValidator("validator-1", &called, true),
6563
},
64+
ExpectedCalls: 1,
65+
Success: true,
6666
},
6767
{
68-
1,
69-
true,
70-
[]ValidatorContext{
68+
Contexts: []ValidatorContext{
7169
MockValidator("no-flag-set", &called, true),
7270
MockValidator("validator-1", &called, true),
7371
},
72+
ExpectedCalls: 1,
73+
Success: true,
7474
},
7575
{
76-
2,
77-
true,
78-
[]ValidatorContext{
76+
Contexts: []ValidatorContext{
7977
MockValidator("validator-1", &called, true),
8078
MockValidator("validator-2", &called, true),
8179
},
80+
ExpectedCalls: 2,
81+
Success: true,
8282
},
8383
{
84-
3,
85-
true,
86-
[]ValidatorContext{
84+
Contexts: []ValidatorContext{
8785
MockValidator("validator-1", &called, true),
8886
MockValidator("validator-2", &called, true),
8987
MockValidator("validator-3", &called, true),
9088
},
89+
ExpectedCalls: 3,
90+
Success: true,
9191
},
9292
{
93-
3,
94-
false,
95-
[]ValidatorContext{
93+
Contexts: []ValidatorContext{
9694
MockValidator("validator-1", &called, false),
9795
MockValidator("validator-2", &called, true),
9896
MockValidator("validator-3", &called, true),
9997
},
98+
ExpectedCalls: 3,
99+
Success: false,
100100
},
101101
{
102-
3,
103-
false,
104-
[]ValidatorContext{
102+
Contexts: []ValidatorContext{
105103
MockValidator("validator-1", &called, true),
106104
MockValidator("validator-2", &called, true),
107105
MockValidator("validator-3", &called, false),
108106
},
107+
ExpectedCalls: 3,
108+
Success: false,
109109
},
110110
}
111111

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

121121
Describe("CLI argument validation", func() {
122122
type testCase struct {
123+
ValidatorContext ValidatorContext
123124
Flag string
124125
Value string
125-
ValidatorContext ValidatorContext
126126
ExpError bool
127127
}
128128

internal/events/event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type UpsertEvent struct {
1717

1818
// DeleteEvent representing deleting a resource.
1919
type DeleteEvent struct {
20-
// NamespacedName is the namespace & name of the deleted resource.
21-
NamespacedName types.NamespacedName
2220
// Type is the resource type. For example, if the event is for *v1beta1.HTTPRoute, pass &v1beta1.HTTPRoute{} as Type.
2321
Type client.Object
22+
// NamespacedName is the namespace & name of the deleted resource.
23+
NamespacedName types.NamespacedName
2424
}

internal/events/first_eventbatch_preparer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ type EachListItemFunc func(obj runtime.Object, fn func(runtime.Object) error) er
3636
// FirstEventBatchPreparerImpl is an implementation of FirstEventBatchPreparer.
3737
type FirstEventBatchPreparerImpl struct {
3838
reader Reader
39+
eachListItem EachListItemFunc
3940
objects []client.Object
4041
objectLists []client.ObjectList
41-
eachListItem EachListItemFunc
4242
}
4343

4444
// NewFirstEventBatchPreparerImpl creates a new FirstEventBatchPreparerImpl.

internal/events/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ type EventHandlerConfig struct {
3535
SecretMemoryManager state.SecretDiskMemoryManager
3636
// Generator is the nginx config Generator.
3737
Generator config.Generator
38-
// Logger is the logger to be used by the EventHandler.
39-
Logger logr.Logger
4038
// NginxFileMgr is the file Manager for nginx.
4139
NginxFileMgr file.Manager
4240
// NginxRuntimeMgr manages nginx runtime.
4341
NginxRuntimeMgr runtime.Manager
4442
// StatusUpdater updates statuses on Kubernetes resources.
4543
StatusUpdater status.Updater
44+
// Logger is the logger to be used by the EventHandler.
45+
Logger logr.Logger
4646
}
4747

4848
// EventHandlerImpl implements EventHandler.

internal/events/loop.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import (
2222
// FIXME(pleshakov): better document the side effects and how to prevent and mitigate them.
2323
// So when the EventLoop have 100 saved events, it is better to process them at once rather than one by one.
2424
type EventLoop struct {
25-
eventCh <-chan interface{}
26-
logger logr.Logger
27-
handler EventHandler
28-
25+
handler EventHandler
2926
preparer FirstEventBatchPreparer
27+
eventCh <-chan interface{}
28+
logger logr.Logger
3029
}
3130

3231
// NewEventLoop creates a new EventLoop.

internal/manager/controllers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func TestRegisterController(t *testing.T) {
4848
tests := []struct {
4949
fakes fakes
5050
expectedErr error
51-
expectedMgrAddCallCount int
5251
msg string
52+
expectedMgrAddCallCount int
5353
}{
5454
{
5555
fakes: getDefaultFakes(),

internal/manager/predicate/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type ServicePortsChangedPredicate struct {
1515

1616
// ports contains the ports that the Gateway cares about.
1717
type ports struct {
18-
servicePort int32
1918
targetPort intstr.IntOrString
19+
servicePort int32
2020
}
2121

2222
// Update implements default UpdateEvent filter for validating Service port changes.

internal/manager/predicate/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111

1212
func TestServicePortsChangedPredicate_Update(t *testing.T) {
1313
testcases := []struct {
14-
msg string
1514
objectOld client.Object
1615
objectNew client.Object
16+
msg string
1717
expUpdate bool
1818
}{
1919
{

0 commit comments

Comments
 (0)