Skip to content

chore: Fix go lint #992

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 2 commits into from
Aug 21, 2023
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
2 changes: 2 additions & 0 deletions internal/framework/status/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func prepareHTTPRouteStatus(
parents := make([]v1beta1.RouteParentStatus, 0, len(status.ParentStatuses))

for _, ps := range status.ParentStatuses {
// reassign the iteration variable inside the loop to fix implicit memory aliasing
ps := ps
p := v1beta1.RouteParentStatus{
ParentRef: v1beta1.ParentReference{
Namespace: (*v1beta1.Namespace)(&ps.GatewayNsName.Namespace),
Expand Down
4 changes: 2 additions & 2 deletions internal/mode/static/nginx/config/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func createHTTPMatch(match dataplane.Match, redirectPath string) httpMatch {
// The name and values are delimited by "=". A name and value can always be recovered using strings.SplitN(arg,"=", 2).
// Query Parameters are case-sensitive so case is preserved.
func createQueryParamKeyValString(p dataplane.HTTPQueryParamMatch) string {
return string(p.Name) + "=" + p.Value
return p.Name + "=" + p.Value
}

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

func isPathOnlyMatch(match dataplane.Match) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,8 @@ func TestCreateHeaderKeyValString(t *testing.T) {

func TestIsPathOnlyMatch(t *testing.T) {
tests := []struct {
match dataplane.Match
msg string
match dataplane.Match
expected bool
}{
{
Expand Down
5 changes: 4 additions & 1 deletion internal/mode/static/state/dataplane/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ func (hpr *hostPathRules) upsertListener(l *graph.Listener) {
rule.PathType = convertPathType(*m.Path.Type)
}

// create iteration variable inside the loop to fix implicit memory aliasing
om := r.Source.ObjectMeta

rule.MatchRules = append(rule.MatchRules, MatchRule{
Source: &r.Source.ObjectMeta,
Source: &om,
BackendGroup: newBackendGroup(r.Rules[i].BackendRefs, routeNsName, i),
Filters: filters,
Match: convertMatch(m),
Expand Down
5 changes: 4 additions & 1 deletion internal/mode/static/state/graph/gateway_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,13 @@ func TestValidateListenerLabelSelector(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
g := NewGomegaWithT(t)

// create iteration variable inside the loop to fix implicit memory aliasing
from := test.from

listener := v1beta1.Listener{
AllowedRoutes: &v1beta1.AllowedRoutes{
Namespaces: &v1beta1.RouteNamespaces{
From: &test.from,
From: &from,
Selector: test.selector,
},
},
Expand Down
4 changes: 3 additions & 1 deletion internal/mode/static/state/graph/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func (r *secretResolver) getResolvedSecrets() map[types.NamespacedName]*Secret {
resolved := make(map[types.NamespacedName]*Secret)

for nsname, entry := range r.resolvedSecrets {
resolved[nsname] = &entry.Secret
// create iteration variable inside the loop to fix implicit memory aliasing
secret := entry.Secret
resolved[nsname] = &secret
}

return resolved
Expand Down