Skip to content

Commit f84d602

Browse files
committed
chore: upgrade golangci lint version to v2
Signed-off-by: ashing <[email protected]>
1 parent 7548a22 commit f84d602

File tree

28 files changed

+495
-130
lines changed

28 files changed

+495
-130
lines changed

.golangci.yml

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
227
- dupl
238
- errcheck
24-
- exportloopref
259
- ginkgolinter
2610
- goconst
2711
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3112
- govet
3213
- ineffassign
3314
- lll
@@ -36,12 +17,34 @@ linters:
3617
- prealloc
3718
- revive
3819
- staticcheck
39-
- typecheck
4020
- unconvert
4121
- unparam
4222
- unused
43-
44-
linters-settings:
45-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
exclusions:
28+
generated: lax
4629
rules:
47-
- name: comment-spacings
30+
- linters:
31+
- lll
32+
path: api/*
33+
- linters:
34+
- dupl
35+
- lll
36+
path: internal/*
37+
paths:
38+
- third_party$
39+
- builtin$
40+
- examples$
41+
formatters:
42+
enable:
43+
- gofmt
44+
- goimports
45+
exclusions:
46+
generated: lax
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$

api/dashboard/v1/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,9 @@ func ComposeConsumerName(namespace, name string) string {
730730
buf := bytes.NewBuffer(p)
731731

732732
// TODO If APISIX modifies the consumer name schema, we can drop this.
733-
buf.WriteString(strings.Replace(namespace, "-", "_", -1))
733+
buf.WriteString(strings.ReplaceAll(namespace, "-", "_"))
734734
buf.WriteString("_")
735-
buf.WriteString(strings.Replace(name, "-", "_", -1))
735+
buf.WriteString(strings.ReplaceAll(name, "-", "_"))
736736

737737
return buf.String()
738738
}

go.sum

Lines changed: 219 additions & 0 deletions
Large diffs are not rendered by default.

internal/controller/consumer_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (r *ConsumerReconciler) checkGatewayRef(object client.Object) bool {
307307
return false
308308
}
309309
gatewayClass := &gatewayv1.GatewayClass{}
310-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
310+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
311311
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
312312
return false
313313
}

internal/controller/gateway_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (r *GatewayReconciler) listGatewayForGatewayClass(ctx context.Context, gate
208208
func (r *GatewayReconciler) checkGatewayClass(obj client.Object) bool {
209209
gateway := obj.(*gatewayv1.Gateway)
210210
gatewayClass := &gatewayv1.GatewayClass{}
211-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
211+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
212212
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
213213
return false
214214
}

internal/controller/ingress_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (r *IngressReconciler) getIngressClass(obj client.Object) (*networkingv1.In
209209

210210
// if it does not match, check if the ingress class is controlled by us
211211
ingressClass := networkingv1.IngressClass{}
212-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: *ingress.Spec.IngressClassName}, &ingressClass); err != nil {
212+
if err := r.Get(context.Background(), client.ObjectKey{Name: *ingress.Spec.IngressClassName}, &ingressClass); err != nil {
213213
return nil, err
214214
}
215215

internal/provider/adc/translator/consumer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package translator
33
import (
44
"encoding/json"
55

6-
"github.com/api7/api7-ingress-controller/api/adc"
76
adctypes "github.com/api7/api7-ingress-controller/api/adc"
87
"github.com/api7/api7-ingress-controller/api/v1alpha1"
98
"github.com/api7/api7-ingress-controller/internal/provider"
@@ -22,7 +21,7 @@ func (t *Translator) TranslateConsumerV1alpha1(tctx *provider.TranslateContext,
2221
}
2322
credentials := make([]adctypes.Credential, 0, len(consumerV.Spec.Credentials))
2423
for _, credentialSpec := range consumerV.Spec.Credentials {
25-
credential := adc.Credential{}
24+
credential := adctypes.Credential{}
2625
credential.Name = credentialSpec.Name
2726
credential.Type = credentialSpec.Type
2827
if credentialSpec.SecretRef != nil {

internal/provider/adc/translator/httproute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func (t *Translator) fillPluginFromHTTPRequestMirrorFilter(plugins adctypes.Plug
180180
}
181181

182182
var (
183-
port int = 80
184-
ns string = namespace
183+
port = 80
184+
ns = namespace
185185
)
186186
if reqMirror.BackendRef.Port != nil {
187187
port = int(*reqMirror.BackendRef.Port)

internal/provider/adc/translator/policies.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package translator
22

33
import (
4-
"github.com/api7/api7-ingress-controller/api/adc"
4+
adctypes "github.com/api7/api7-ingress-controller/api/adc"
55
"github.com/api7/api7-ingress-controller/api/v1alpha1"
66
"k8s.io/apimachinery/pkg/types"
77
"k8s.io/utils/ptr"
88
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
9-
10-
adctypes "github.com/api7/api7-ingress-controller/api/adc"
119
)
1210

1311
func convertBackendRef(namespace, name, kind string) gatewayv1.BackendRef {
@@ -53,13 +51,13 @@ func (t *Translator) attachBackendTrafficPolicyToUpstream(policy *v1alpha1.Backe
5351
}
5452
if policy.Spec.Timeout != nil {
5553
upstream.Timeout = &adctypes.Timeout{
56-
Connect: int(policy.Spec.Timeout.Connect.Duration.Seconds()),
57-
Read: int(policy.Spec.Timeout.Read.Duration.Seconds()),
58-
Send: int(policy.Spec.Timeout.Send.Duration.Seconds()),
54+
Connect: int(policy.Spec.Timeout.Connect.Seconds()),
55+
Read: int(policy.Spec.Timeout.Read.Seconds()),
56+
Send: int(policy.Spec.Timeout.Send.Seconds()),
5957
}
6058
}
6159
if policy.Spec.LoadBalancer != nil {
62-
upstream.Type = adc.UpstreamType(policy.Spec.LoadBalancer.Type)
60+
upstream.Type = adctypes.UpstreamType(policy.Spec.LoadBalancer.Type)
6361
upstream.HashOn = policy.Spec.LoadBalancer.HashOn
6462
upstream.Key = policy.Spec.LoadBalancer.Key
6563
}

internal/provider/controlplane/translator/httproute.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func (t *Translator) fillPluginFromHTTPRequestMirrorFilter(plugins v1.Plugins, n
167167
}
168168

169169
var (
170-
port int = 80
171-
ns string = namespace
170+
port = 80
171+
ns = namespace
172172
)
173173
if reqMirror.BackendRef.Port != nil {
174174
port = int(*reqMirror.BackendRef.Port)
@@ -273,8 +273,8 @@ func (t *Translator) TranslateHTTPRoute(tctx *provider.TranslateContext, httpRou
273273
backend.Namespace = &namespace
274274
}
275275
upstream := t.translateBackendRef(tctx, backend.BackendRef)
276-
upstream.Labels["name"] = string(backend.BackendRef.Name)
277-
upstream.Labels["namespace"] = string(*backend.BackendRef.Namespace)
276+
upstream.Labels["name"] = string(backend.Name)
277+
upstream.Labels["namespace"] = string(*backend.Namespace)
278278
upstreams = append(upstreams, upstream)
279279
if len(upstream.Nodes) == 0 {
280280
upstream.Nodes = v1.UpstreamNodes{
@@ -389,7 +389,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
389389
}
390390
}
391391

392-
if match.Headers != nil && len(match.Headers) > 0 {
392+
if len(match.Headers) > 0 {
393393
for _, header := range match.Headers {
394394
name := strings.ToLower(string(header.Name))
395395
name = strings.ReplaceAll(name, "-", "_")
@@ -420,7 +420,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
420420
}
421421
}
422422

423-
if match.QueryParams != nil && len(match.QueryParams) > 0 {
423+
if len(match.QueryParams) > 0 {
424424
for _, query := range match.QueryParams {
425425
var this []v1.StringOrSlice
426426
this = append(this, v1.StringOrSlice{

0 commit comments

Comments
 (0)