chore: update linter
This commit is contained in:
parent
1034646ae2
commit
88a2020817
57 changed files with 139 additions and 218 deletions
|
@ -1,6 +1,8 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/go-acme/lego/v4/challenge/tlsalpn01"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
|
@ -91,7 +93,7 @@ func mergeConfiguration(configurations dynamic.Configurations, defaultEntryPoint
|
|||
|
||||
if configuration.TLS != nil {
|
||||
for _, cert := range configuration.TLS.Certificates {
|
||||
if containsACMETLS1(cert.Stores) && pvd != "tlsalpn.acme" {
|
||||
if slices.Contains(cert.Stores, tlsalpn01.ACMETLS1Protocol) && pvd != "tlsalpn.acme" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -179,13 +181,3 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
|
|||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func containsACMETLS1(stores []string) bool {
|
||||
for _, store := range stores {
|
||||
if store == tlsalpn01.ACMETLS1Protocol {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ func TestListenProvidersThrottleProviderConfigReload(t *testing.T) {
|
|||
throttleDuration: 30 * time.Millisecond,
|
||||
}
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
pvd.messages = append(pvd.messages, dynamic.Message{
|
||||
ProviderName: "mock",
|
||||
Configuration: &dynamic.Configuration{
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/alice"
|
||||
|
@ -97,7 +98,7 @@ func checkRecursion(ctx context.Context, middlewareName string) (context.Context
|
|||
if !ok {
|
||||
currentStack = []string{}
|
||||
}
|
||||
if inSlice(middlewareName, currentStack) {
|
||||
if slices.Contains(currentStack, middlewareName) {
|
||||
return ctx, fmt.Errorf("could not instantiate middleware %s: recursion detected in %s", middlewareName, strings.Join(append(currentStack, middlewareName), "->"))
|
||||
}
|
||||
return context.WithValue(ctx, middlewareStackKey, append(currentStack, middlewareName)), nil
|
||||
|
@ -381,12 +382,3 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) (
|
|||
|
||||
return tracing.Wrap(ctx, middleware), nil
|
||||
}
|
||||
|
||||
func inSlice(element string, stack []string) bool {
|
||||
for _, value := range stack {
|
||||
if value == element {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package tcpmiddleware
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/config/runtime"
|
||||
|
@ -74,7 +75,7 @@ func checkRecursion(ctx context.Context, middlewareName string) (context.Context
|
|||
currentStack = []string{}
|
||||
}
|
||||
|
||||
if inSlice(middlewareName, currentStack) {
|
||||
if slices.Contains(currentStack, middlewareName) {
|
||||
return ctx, fmt.Errorf("could not instantiate middleware %s: recursion detected in %s", middlewareName, strings.Join(append(currentStack, middlewareName), "->"))
|
||||
}
|
||||
|
||||
|
@ -117,12 +118,3 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) (
|
|||
|
||||
return middleware, nil
|
||||
}
|
||||
|
||||
func inSlice(element string, stack []string) bool {
|
||||
for _, value := range stack {
|
||||
if value == element {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -945,7 +945,7 @@ func BenchmarkRouterServe(b *testing.B) {
|
|||
|
||||
reqHost := requestdecorator.New(nil)
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
reqHost.ServeHTTP(w, req, handlers["web"].ServeHTTP)
|
||||
}
|
||||
}
|
||||
|
@ -980,7 +980,7 @@ func BenchmarkService(b *testing.B) {
|
|||
|
||||
handler, _ := serviceManager.BuildHTTP(context.Background(), "foo-service")
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
handler.ServeHTTP(w, req)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ func testShutdown(t *testing.T, router *tcprouter.Router) {
|
|||
// but technically also as early as the Shutdown has closed the listener,
|
||||
// i.e. during the shutdown and before the gracetime is over.
|
||||
var testOk bool
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
loopConn, err := net.Dial("tcp", epAddr)
|
||||
if err == nil {
|
||||
loopConn.Close()
|
||||
|
@ -141,7 +141,7 @@ func startEntrypoint(entryPoint *TCPEntryPoint, router *tcprouter.Router) (net.C
|
|||
|
||||
entryPoint.SwitchRouter(router)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
conn, err := net.Dial("tcp", entryPoint.listener.Addr().String())
|
||||
if err != nil {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
|
|
@ -32,7 +32,7 @@ func TestMirroringOn100(t *testing.T) {
|
|||
}), 50)
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
mirror.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ func TestMirroringOn10(t *testing.T) {
|
|||
}), 50)
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
mirror.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ func TestMirroringWithBody(t *testing.T) {
|
|||
|
||||
mirror := New(handler, pool, defaultMaxBodySize, nil)
|
||||
|
||||
for i := 0; i < numMirrors; i++ {
|
||||
for range numMirrors {
|
||||
err := mirror.AddMirror(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
assert.NotNil(t, r.Body)
|
||||
bb, err := io.ReadAll(r.Body)
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestBalancer(t *testing.T) {
|
|||
}), Int(1))
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 4; i++ {
|
||||
for range 4 {
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ func TestBalancerOneServerZeroWeight(t *testing.T) {
|
|||
balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), Int(0))
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ func TestBalancerOneServerDown(t *testing.T) {
|
|||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
|
||||
|
@ -135,14 +135,14 @@ func TestBalancerDownThenUp(t *testing.T) {
|
|||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
assert.Equal(t, 3, recorder.save["first"])
|
||||
|
||||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", true)
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 2; i++ {
|
||||
for range 2 {
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
assert.Equal(t, 1, recorder.save["first"])
|
||||
|
@ -184,7 +184,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
})
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 8; i++ {
|
||||
for range 8 {
|
||||
topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
assert.Equal(t, 2, recorder.save["first"])
|
||||
|
@ -197,7 +197,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
// fourth gets downed, but balancer2 still up since third is still up.
|
||||
balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "fourth", false)
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 8; i++ {
|
||||
for range 8 {
|
||||
topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
assert.Equal(t, 2, recorder.save["first"])
|
||||
|
@ -211,7 +211,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
// down as well for topBalancer.
|
||||
balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "third", false)
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for i := 0; i < 8; i++ {
|
||||
for range 8 {
|
||||
topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
assert.Equal(t, 4, recorder.save["first"])
|
||||
|
@ -252,7 +252,7 @@ func TestSticky(t *testing.T) {
|
|||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
for _, cookie := range recorder.Result().Cookies() {
|
||||
assert.NotContains(t, "test=first", cookie.Value)
|
||||
assert.NotContains(t, "test=second", cookie.Value)
|
||||
|
@ -286,7 +286,7 @@ func TestSticky_FallBack(t *testing.T) {
|
|||
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
req.AddCookie(&http.Cookie{Name: "test", Value: "second"})
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
recorder.ResponseRecorder = httptest.NewRecorder()
|
||||
|
||||
balancer.ServeHTTP(recorder, req)
|
||||
|
@ -313,7 +313,7 @@ func TestBalancerBias(t *testing.T) {
|
|||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
|
||||
for i := 0; i < 14; i++ {
|
||||
for range 14 {
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ func BenchmarkProxy(b *testing.B) {
|
|||
handler, _ := buildProxy(Bool(false), nil, &staticTransport{res}, pool)
|
||||
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
handler.ServeHTTP(w, req)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -210,12 +211,9 @@ func (k *KerberosRoundTripper) RoundTrip(request *http.Request) (*http.Response,
|
|||
}
|
||||
|
||||
func containsNTLMorNegotiate(h []string) bool {
|
||||
for _, s := range h {
|
||||
if strings.HasPrefix(s, "NTLM") || strings.HasPrefix(s, "Negotiate") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.ContainsFunc(h, func(s string) bool {
|
||||
return strings.HasPrefix(s, "NTLM") || strings.HasPrefix(s, "Negotiate")
|
||||
})
|
||||
}
|
||||
|
||||
func createRootCACertPool(rootCAs []traefiktls.FileOrContent) *x509.CertPool {
|
||||
|
|
|
@ -139,7 +139,7 @@ func TestKeepConnectionWhenSameConfiguration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
rtManager.Update(dynamicConf)
|
||||
|
||||
tr, err := rtManager.Get("test")
|
||||
|
|
|
@ -85,7 +85,7 @@ func (m *Manager) BuildHTTP(rootCtx context.Context, serviceName string) (http.H
|
|||
|
||||
value := reflect.ValueOf(*conf.Service)
|
||||
var count int
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
for i := range value.NumField() {
|
||||
if !value.Field(i).IsNil() {
|
||||
count++
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue