Update to go1.22
Co-authored-by: Julien Salleyron <julien.salleyron@gmail.com>
This commit is contained in:
parent
e11ff98608
commit
d5cb9b50f4
56 changed files with 4189 additions and 3419 deletions
|
@ -20,8 +20,6 @@ import (
|
|||
const collectorURL = "https://collect.traefik.io/9vxmmkcdmalbdi635d4jgc5p5rx0h7h8"
|
||||
|
||||
// Collected data.
|
||||
//
|
||||
//nolint:musttag // cannot be changed for historical reasons.
|
||||
type data struct {
|
||||
Version string
|
||||
Codename string
|
||||
|
@ -67,7 +65,7 @@ func createBody(staticConfiguration *static.Configuration) (*bytes.Buffer, error
|
|||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
err = json.NewEncoder(buf).Encode(data)
|
||||
err = json.NewEncoder(buf).Encode(data) //nolint:musttag // cannot be changed for historical reasons.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package runtime
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
|
@ -42,7 +43,7 @@ func (c *Configuration) GetRoutersByEntryPoints(ctx context.Context, entryPoints
|
|||
}
|
||||
|
||||
if entryPointsCount == 0 {
|
||||
rt.AddError(fmt.Errorf("no valid entryPoint for this router"), true)
|
||||
rt.AddError(errors.New("no valid entryPoint for this router"), true)
|
||||
logger.Error("no valid entryPoint for this router")
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package runtime
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
|
@ -36,7 +37,7 @@ func (c *Configuration) GetTCPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
}
|
||||
|
||||
if entryPointsCount == 0 {
|
||||
rt.AddError(fmt.Errorf("no valid entryPoint for this router"), true)
|
||||
rt.AddError(errors.New("no valid entryPoint for this router"), true)
|
||||
logger.Error("no valid entryPoint for this router")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package runtime
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
|
@ -42,7 +43,7 @@ func (c *Configuration) GetUDPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
}
|
||||
|
||||
if entryPointsCount == 0 {
|
||||
rt.AddError(fmt.Errorf("no valid entryPoint for this router"), true)
|
||||
rt.AddError(errors.New("no valid entryPoint for this router"), true)
|
||||
logger.Error("no valid entryPoint for this router")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package static
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
stdlog "log"
|
||||
"strings"
|
||||
|
@ -304,15 +305,15 @@ func (c *Configuration) ValidateConfiguration() error {
|
|||
}
|
||||
|
||||
if c.Providers.ConsulCatalog != nil && c.Providers.ConsulCatalog.Namespace != "" && len(c.Providers.ConsulCatalog.Namespaces) > 0 {
|
||||
return fmt.Errorf("Consul Catalog provider cannot have both namespace and namespaces options configured")
|
||||
return errors.New("Consul Catalog provider cannot have both namespace and namespaces options configured")
|
||||
}
|
||||
|
||||
if c.Providers.Consul != nil && c.Providers.Consul.Namespace != "" && len(c.Providers.Consul.Namespaces) > 0 {
|
||||
return fmt.Errorf("Consul provider cannot have both namespace and namespaces options configured")
|
||||
return errors.New("Consul provider cannot have both namespace and namespaces options configured")
|
||||
}
|
||||
|
||||
if c.Providers.Nomad != nil && c.Providers.Nomad.Namespace != "" && len(c.Providers.Nomad.Namespaces) > 0 {
|
||||
return fmt.Errorf("Nomad provider cannot have both namespace and namespaces options configured")
|
||||
return errors.New("Nomad provider cannot have both namespace and namespaces options configured")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -25,6 +25,8 @@ import (
|
|||
"github.com/traefik/traefik/v2/pkg/types"
|
||||
)
|
||||
|
||||
const delta float64 = 1e-10
|
||||
|
||||
var (
|
||||
logFileNameSuffix = "/traefik/logger/test.log"
|
||||
testContent = "Hello, World"
|
||||
|
@ -278,7 +280,7 @@ func assertFloat64(exp float64) func(t *testing.T, actual interface{}) {
|
|||
return func(t *testing.T, actual interface{}) {
|
||||
t.Helper()
|
||||
|
||||
assert.Equal(t, exp, actual)
|
||||
assert.InDelta(t, exp, actual, delta)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package addprefix
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
@ -35,7 +35,7 @@ func New(ctx context.Context, next http.Handler, config dynamic.AddPrefix, name
|
|||
name: name,
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("prefix cannot be empty")
|
||||
return nil, errors.New("prefix cannot be empty")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
|
|
@ -298,7 +298,7 @@ func TestNewResponseRecorder(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
rec := newCodeModifier(test.rw, 0)
|
||||
assert.IsType(t, rec, test.expected)
|
||||
assert.IsType(t, test.expected, rec)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -374,7 +374,7 @@ func hostSNI(tree *matchersTree, hosts ...string) error {
|
|||
// hostSNIRegexp checks if the SNI Host of the connection matches the matcher host regexp.
|
||||
func hostSNIRegexp(tree *matchersTree, templates ...string) error {
|
||||
if len(templates) == 0 {
|
||||
return fmt.Errorf("empty value for \"HostSNIRegexp\" matcher is not allowed")
|
||||
return errors.New("empty value for \"HostSNIRegexp\" matcher is not allowed")
|
||||
}
|
||||
|
||||
var regexps []*regexp.Regexp
|
||||
|
|
|
@ -230,7 +230,7 @@ func (c *Client) Check(ctx context.Context, pName, pVersion, hash string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("plugin integrity check failed")
|
||||
return errors.New("plugin integrity check failed")
|
||||
}
|
||||
|
||||
// Unzip unzip a plugin archive.
|
||||
|
|
|
@ -2,6 +2,7 @@ package http
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
|
@ -41,11 +42,11 @@ func (p *Provider) SetDefaults() {
|
|||
// Init the provider.
|
||||
func (p *Provider) Init() error {
|
||||
if p.Endpoint == "" {
|
||||
return fmt.Errorf("non-empty endpoint is required")
|
||||
return errors.New("non-empty endpoint is required")
|
||||
}
|
||||
|
||||
if p.PollInterval <= 0 {
|
||||
return fmt.Errorf("poll interval must be greater than 0")
|
||||
return errors.New("poll interval must be greater than 0")
|
||||
}
|
||||
|
||||
p.httpClient = &http.Client{
|
||||
|
|
|
@ -51,6 +51,7 @@ type sharedInformerFactory struct {
|
|||
lock sync.Mutex
|
||||
defaultResync time.Duration
|
||||
customResync map[reflect.Type]time.Duration
|
||||
transform cache.TransformFunc
|
||||
|
||||
informers map[reflect.Type]cache.SharedIndexInformer
|
||||
// startedInformers is used for tracking which informers have been started.
|
||||
|
@ -89,6 +90,14 @@ func WithNamespace(namespace string) SharedInformerOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithTransform sets a transform on all informers.
|
||||
func WithTransform(transform cache.TransformFunc) SharedInformerOption {
|
||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
||||
factory.transform = transform
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
|
||||
func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
|
||||
return NewSharedInformerFactoryWithOptions(client, defaultResync)
|
||||
|
@ -193,6 +202,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
|
|||
}
|
||||
|
||||
informer = newFunc(f.client, resyncPeriod)
|
||||
informer.SetTransform(f.transform)
|
||||
f.informers[informerType] = informer
|
||||
|
||||
return informer
|
||||
|
|
|
@ -641,7 +641,7 @@ func createForwardAuthMiddleware(k8sClient Client, namespace string, auth *traef
|
|||
return nil, nil
|
||||
}
|
||||
if len(auth.Address) == 0 {
|
||||
return nil, fmt.Errorf("forward authentication requires an address")
|
||||
return nil, errors.New("forward authentication requires an address")
|
||||
}
|
||||
|
||||
forwardAuth := &dynamic.ForwardAuth{
|
||||
|
@ -734,7 +734,7 @@ func createBasicAuthMiddleware(client Client, namespace string, basicAuth *traef
|
|||
}
|
||||
|
||||
if basicAuth.Secret == "" {
|
||||
return nil, fmt.Errorf("auth secret must be set")
|
||||
return nil, errors.New("auth secret must be set")
|
||||
}
|
||||
|
||||
secret, ok, err := client.GetSecret(namespace, basicAuth.Secret)
|
||||
|
@ -781,7 +781,7 @@ func createDigestAuthMiddleware(client Client, namespace string, digestAuth *tra
|
|||
}
|
||||
|
||||
if digestAuth.Secret == "" {
|
||||
return nil, fmt.Errorf("auth secret must be set")
|
||||
return nil, errors.New("auth secret must be set")
|
||||
}
|
||||
|
||||
secret, ok, err := client.GetSecret(namespace, digestAuth.Secret)
|
||||
|
|
|
@ -2,7 +2,7 @@ package ingress
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -40,9 +40,9 @@ func TestTranslateNotFoundError(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "not a kubernetes not found error",
|
||||
err: fmt.Errorf("bar error"),
|
||||
err: errors.New("bar error"),
|
||||
expectedExists: false,
|
||||
expectedError: fmt.Errorf("bar error"),
|
||||
expectedError: errors.New("bar error"),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package safe
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -146,7 +146,7 @@ func TestOperationWithRecoverPanic(t *testing.T) {
|
|||
|
||||
func TestOperationWithRecoverError(t *testing.T) {
|
||||
operation := func() error {
|
||||
return fmt.Errorf("ERROR")
|
||||
return errors.New("ERROR")
|
||||
}
|
||||
err := backoff.Retry(OperationWithRecover(operation), &backoff.StopBackOff{})
|
||||
if err == nil {
|
||||
|
|
|
@ -2,7 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
|
@ -30,7 +30,7 @@ func (p *mockProvider) Provide(configurationChan chan<- dynamic.Message, _ *safe
|
|||
}
|
||||
|
||||
if len(p.messages) == 0 {
|
||||
return fmt.Errorf("no messages available")
|
||||
return errors.New("no messages available")
|
||||
}
|
||||
|
||||
configurationChan <- p.messages[0]
|
||||
|
|
|
@ -171,9 +171,11 @@ func Test_Routing(t *testing.T) {
|
|||
map[string]traefiktls.Store{},
|
||||
map[string]traefiktls.Options{
|
||||
"default": {
|
||||
MinVersion: "VersionTLS10",
|
||||
MaxVersion: "VersionTLS10",
|
||||
},
|
||||
"tls10": {
|
||||
MinVersion: "VersionTLS10",
|
||||
MaxVersion: "VersionTLS10",
|
||||
},
|
||||
"tls12": {
|
||||
|
|
|
@ -381,7 +381,7 @@ func writeCloser(conn net.Conn) (tcp.WriteCloser, error) {
|
|||
case *proxyproto.Conn:
|
||||
underlying, ok := typedConn.TCPConn()
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("underlying connection is not a tcp connection")
|
||||
return nil, errors.New("underlying connection is not a tcp connection")
|
||||
}
|
||||
return &writeCloserWrapper{writeCloser: underlying, Conn: typedConn}, nil
|
||||
case *net.TCPConn:
|
||||
|
@ -632,7 +632,6 @@ func createHTTPServer(ctx context.Context, ln net.Listener, configuration *stati
|
|||
MaxConcurrentStreams: uint32(configuration.HTTP2.MaxConcurrentStreams),
|
||||
NewWriteScheduler: func() http2.WriteScheduler { return http2.NewPriorityWriteScheduler(nil) },
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("configure HTTP/2 server: %w", err)
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"container/heap"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
|
@ -156,7 +156,7 @@ func (b *Balancer) nextServer() (*namedHandler, error) {
|
|||
defer b.handlersMu.Unlock()
|
||||
|
||||
if len(b.handlers) == 0 {
|
||||
return nil, fmt.Errorf("no servers in the pool")
|
||||
return nil, errors.New("no servers in the pool")
|
||||
}
|
||||
if len(b.status) == 0 {
|
||||
return nil, errNoAvailableServer
|
||||
|
@ -252,5 +252,5 @@ func hash(input string) string {
|
|||
// We purposely ignore the error because the implementation always returns nil.
|
||||
_, _ = hasher.Write([]byte(input))
|
||||
|
||||
return fmt.Sprintf("%x", hasher.Sum64())
|
||||
return strconv.FormatUint(hasher.Sum64(), 16)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package tcp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Constructor A constructor for a piece of TCP middleware.
|
||||
|
@ -29,7 +29,7 @@ func NewChain(constructors ...Constructor) Chain {
|
|||
// Then adds an handler at the end of the chain.
|
||||
func (c Chain) Then(h Handler) (Handler, error) {
|
||||
if h == nil {
|
||||
return nil, fmt.Errorf("cannot add a nil handler to the chain")
|
||||
return nil, errors.New("cannot add a nil handler to the chain")
|
||||
}
|
||||
|
||||
for i := range c.constructors {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package tcp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
|
@ -91,7 +91,7 @@ func gcd(a, b int) int {
|
|||
|
||||
func (b *WRRLoadBalancer) next() (Handler, error) {
|
||||
if len(b.servers) == 0 {
|
||||
return nil, fmt.Errorf("no servers in the pool")
|
||||
return nil, errors.New("no servers in the pool")
|
||||
}
|
||||
|
||||
// The algo below may look messy, but is actually very simple
|
||||
|
@ -101,7 +101,7 @@ func (b *WRRLoadBalancer) next() (Handler, error) {
|
|||
// Maximum weight across all enabled servers
|
||||
max := b.maxWeight()
|
||||
if max == 0 {
|
||||
return nil, fmt.Errorf("all servers have 0 weight")
|
||||
return nil, errors.New("all servers have 0 weight")
|
||||
}
|
||||
|
||||
// GCD across all enabled servers
|
||||
|
|
|
@ -333,10 +333,6 @@ func TestManager_Get_DefaultValues(t *testing.T) {
|
|||
assert.Equal(t, uint16(tls.VersionTLS12), config.MinVersion)
|
||||
assert.Equal(t, []string{"h2", "http/1.1", "acme-tls/1"}, config.NextProtos)
|
||||
assert.Equal(t, []uint16{
|
||||
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
|
||||
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
|
||||
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_AES_128_GCM_SHA256,
|
||||
tls.TLS_AES_256_GCM_SHA384,
|
||||
tls.TLS_CHACHA20_POLY1305_SHA256,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package udp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
|
@ -91,7 +91,7 @@ func gcd(a, b int) int {
|
|||
|
||||
func (b *WRRLoadBalancer) next() (Handler, error) {
|
||||
if len(b.servers) == 0 {
|
||||
return nil, fmt.Errorf("no servers in the pool")
|
||||
return nil, errors.New("no servers in the pool")
|
||||
}
|
||||
|
||||
// The algorithm below may look messy,
|
||||
|
@ -101,7 +101,7 @@ func (b *WRRLoadBalancer) next() (Handler, error) {
|
|||
// Maximum weight across all enabled servers
|
||||
max := b.maxWeight()
|
||||
if max == 0 {
|
||||
return nil, fmt.Errorf("all servers have 0 weight")
|
||||
return nil, errors.New("all servers have 0 weight")
|
||||
}
|
||||
|
||||
// GCD across all enabled servers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue