Skip to content

Commit f3e31b9

Browse files
committed
chore: Fix go lint (nginx#992)
* Fix go lint
1 parent 010781a commit f3e31b9

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

internal/framework/status/httproute.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func prepareHTTPRouteStatus(
1414
parents := make([]v1beta1.RouteParentStatus, 0, len(status.ParentStatuses))
1515

1616
for _, ps := range status.ParentStatuses {
17+
// reassign the iteration variable inside the loop to fix implicit memory aliasing
18+
ps := ps
1719
p := v1beta1.RouteParentStatus{
1820
ParentRef: v1beta1.ParentReference{
1921
Namespace: (*v1beta1.Namespace)(&ps.GatewayNsName.Namespace),

internal/mode/static/nginx/config/servers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func createHTTPMatch(match dataplane.Match, redirectPath string) httpMatch {
338338
// The name and values are delimited by "=". A name and value can always be recovered using strings.SplitN(arg,"=", 2).
339339
// Query Parameters are case-sensitive so case is preserved.
340340
func createQueryParamKeyValString(p dataplane.HTTPQueryParamMatch) string {
341-
return string(p.Name) + "=" + p.Value
341+
return p.Name + "=" + p.Value
342342
}
343343

344344
// The name and values are delimited by ":". A name and value can always be recovered using strings.Split(arg, ":").
@@ -347,7 +347,7 @@ func createQueryParamKeyValString(p dataplane.HTTPQueryParamMatch) string {
347347
// We preserve the case of the name here because NGINX allows us to look up the header names in a case-insensitive
348348
// manner.
349349
func createHeaderKeyValString(h dataplane.HTTPHeaderMatch) string {
350-
return string(h.Name) + HeaderMatchSeparator + h.Value
350+
return h.Name + HeaderMatchSeparator + h.Value
351351
}
352352

353353
func isPathOnlyMatch(match dataplane.Match) bool {

internal/mode/static/nginx/config/servers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,8 @@ func TestCreateHeaderKeyValString(t *testing.T) {
13101310

13111311
func TestIsPathOnlyMatch(t *testing.T) {
13121312
tests := []struct {
1313-
match dataplane.Match
13141313
msg string
1314+
match dataplane.Match
13151315
expected bool
13161316
}{
13171317
{

internal/mode/static/state/dataplane/configuration.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ func (hpr *hostPathRules) upsertListener(l *graph.Listener) {
248248
rule.PathType = convertPathType(*m.Path.Type)
249249
}
250250

251+
// create iteration variable inside the loop to fix implicit memory aliasing
252+
om := r.Source.ObjectMeta
253+
251254
rule.MatchRules = append(rule.MatchRules, MatchRule{
252-
Source: &r.Source.ObjectMeta,
255+
Source: &om,
253256
BackendGroup: newBackendGroup(r.Rules[i].BackendRefs, routeNsName, i),
254257
Filters: filters,
255258
Match: convertMatch(m),

internal/mode/static/state/graph/gateway_listener_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,13 @@ func TestValidateListenerLabelSelector(t *testing.T) {
364364
t.Run(test.name, func(t *testing.T) {
365365
g := NewGomegaWithT(t)
366366

367+
// create iteration variable inside the loop to fix implicit memory aliasing
368+
from := test.from
369+
367370
listener := v1beta1.Listener{
368371
AllowedRoutes: &v1beta1.AllowedRoutes{
369372
Namespaces: &v1beta1.RouteNamespaces{
370-
From: &test.from,
373+
From: &from,
371374
Selector: test.selector,
372375
},
373376
},

internal/mode/static/state/graph/secret.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ func (r *secretResolver) getResolvedSecrets() map[types.NamespacedName]*Secret {
7474
resolved := make(map[types.NamespacedName]*Secret)
7575

7676
for nsname, entry := range r.resolvedSecrets {
77-
resolved[nsname] = &entry.Secret
77+
// create iteration variable inside the loop to fix implicit memory aliasing
78+
secret := entry.Secret
79+
resolved[nsname] = &secret
7880
}
7981

8082
return resolved

0 commit comments

Comments
 (0)