Skip to content

Commit f82a192

Browse files
committed
Enable govet fieldalignment linter (nginx#284)
Enable fieldalignment and fix errors
1 parent d6e6f39 commit f82a192

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
{

internal/nginx/config/http/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type Location struct {
2020

2121
// Return represents an HTTP return.
2222
type Return struct {
23-
Code StatusCode
2423
URL string
24+
Code StatusCode
2525
}
2626

2727
// SSL holds all SSL related configuration.

internal/nginx/config/servers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ func createReturnValForRedirectFilter(filter *v1beta1.HTTPRequestRedirectFilter,
181181
// 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.
182182
// If the request satisfies the httpMatch, the request will be internally redirected to the location RedirectPath by NGINX.
183183
type httpMatch struct {
184-
// Any represents a match with no match conditions.
185-
Any bool `json:"any,omitempty"`
186184
// Method is the HTTPMethod of the HTTPRouteMatch.
187185
Method v1beta1.HTTPMethod `json:"method,omitempty"`
186+
// RedirectPath is the path to redirect the request to if the request satisfies the match conditions.
187+
RedirectPath string `json:"redirectPath,omitempty"`
188188
// Headers is a list of HTTPHeaders name value pairs with the format "{name}:{value}".
189189
Headers []string `json:"headers,omitempty"`
190190
// QueryParams is a list of HTTPQueryParams name value pairs with the format "{name}={value}".
191191
QueryParams []string `json:"params,omitempty"`
192-
// RedirectPath is the path to redirect the request to if the request satisfies the match conditions.
193-
RedirectPath string `json:"redirectPath,omitempty"`
192+
// Any represents a match with no match conditions.
193+
Any bool `json:"any,omitempty"`
194194
}
195195

196196
func createHTTPMatch(match v1beta1.HTTPRouteMatch, redirectPath string) httpMatch {

internal/nginx/config/servers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func TestExecuteServers(t *testing.T) {
6767

6868
func TestExecuteForDefaultServers(t *testing.T) {
6969
testcases := []struct {
70+
msg string
7071
conf state.Configuration
7172
httpDefault bool
7273
sslDefault bool
73-
msg string
7474
}{
7575
{
7676
conf: state.Configuration{},
@@ -624,8 +624,8 @@ func TestCreateHTTPMatch(t *testing.T) {
624624

625625
tests := []struct {
626626
match v1beta1.HTTPRouteMatch
627-
expected httpMatch
628627
msg string
628+
expected httpMatch
629629
}{
630630
{
631631
match: v1beta1.HTTPRouteMatch{
@@ -781,8 +781,8 @@ func TestCreateHeaderKeyValString(t *testing.T) {
781781
func TestIsPathOnlyMatch(t *testing.T) {
782782
tests := []struct {
783783
match v1beta1.HTTPRouteMatch
784-
expected bool
785784
msg string
785+
expected bool
786786
}{
787787
{
788788
match: v1beta1.HTTPRouteMatch{

internal/nginx/config/split_clients_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ func TestCreateSplitClientDistributions(t *testing.T) {
405405
func TestGetSplitClientValue(t *testing.T) {
406406
tests := []struct {
407407
msg string
408-
backend state.BackendRef
409408
expValue string
409+
backend state.BackendRef
410410
}{
411411
{
412412
msg: "valid backend",
@@ -598,8 +598,8 @@ func TestBackendGroupNeedsSplit(t *testing.T) {
598598
func TestBackendGroupName(t *testing.T) {
599599
tests := []struct {
600600
msg string
601-
backends []state.BackendRef
602601
expName string
602+
backends []state.BackendRef
603603
}{
604604
{
605605
msg: "empty backends",

internal/nginx/config/upstreams_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ func TestCreateUpstreams(t *testing.T) {
142142

143143
func TestCreateUpstream(t *testing.T) {
144144
tests := []struct {
145+
msg string
145146
stateUpstream state.Upstream
146147
expectedUpstream http.Upstream
147-
msg string
148148
}{
149149
{
150150
stateUpstream: state.Upstream{

internal/nginx/runtime/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ func TestFindMainProcess(t *testing.T) {
2020

2121
tests := []struct {
2222
readFile readFileFunc
23+
msg string
2324
expected int
2425
expectError bool
25-
msg string
2626
}{
2727
{
2828
readFile: readFileFuncGen([]byte("1\n")),

internal/state/backend_group.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import (
99

1010
// BackendGroup represents a group of backends for a rule in an HTTPRoute.
1111
type BackendGroup struct {
12-
Errors []string
1312
Source types.NamespacedName
14-
RuleIdx int
13+
Errors []string
1514
Backends []BackendRef
15+
RuleIdx int
1616
}
1717

1818
// BackendRef is an internal representation of a backendRef in an HTTPRoute.
1919
type BackendRef struct {
20-
Name string
2120
Svc *v1.Service
21+
Name string
2222
Port int32
23-
Valid bool
2423
Weight int32
24+
Valid bool
2525
}
2626

2727
// GroupName returns the name of the backend group.

internal/state/backend_refs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func getModifiedRef(mod func(ref v1beta1.BackendRef) v1beta1.BackendRef) v1beta1
3131

3232
func TestValidateBackendRef(t *testing.T) {
3333
tests := []struct {
34-
msg string
3534
ref v1beta1.BackendRef
35+
msg string
3636
expErr bool
3737
}{
3838
{
@@ -107,9 +107,9 @@ func TestGetServiceAndPortFromRef(t *testing.T) {
107107
}
108108

109109
tests := []struct {
110-
msg string
111110
ref v1beta1.BackendRef
112111
expService *v1.Service
112+
msg string
113113
expPort int32
114114
expErr bool
115115
}{

0 commit comments

Comments
 (0)