mirror of
https://github.com/traefik/traefik.git
synced 2025-05-05 23:43:01 +00:00
Replace experimental maps and slices with stdlib
This commit is contained in:
parent
68a8650297
commit
aa8eb1af6e
@ -7,10 +7,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
stdlog "log"
|
stdlog "log"
|
||||||
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sort"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -48,7 +49,6 @@ import (
|
|||||||
"github.com/traefik/traefik/v3/pkg/tracing"
|
"github.com/traefik/traefik/v3/pkg/tracing"
|
||||||
"github.com/traefik/traefik/v3/pkg/types"
|
"github.com/traefik/traefik/v3/pkg/types"
|
||||||
"github.com/traefik/traefik/v3/pkg/version"
|
"github.com/traefik/traefik/v3/pkg/version"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -232,8 +232,8 @@ func setupServer(staticConfiguration *static.Configuration) (*server.Server, err
|
|||||||
pluginLogger := log.Ctx(ctx).With().Logger()
|
pluginLogger := log.Ctx(ctx).With().Logger()
|
||||||
hasPlugins := staticConfiguration.Experimental != nil && (staticConfiguration.Experimental.Plugins != nil || staticConfiguration.Experimental.LocalPlugins != nil)
|
hasPlugins := staticConfiguration.Experimental != nil && (staticConfiguration.Experimental.Plugins != nil || staticConfiguration.Experimental.LocalPlugins != nil)
|
||||||
if hasPlugins {
|
if hasPlugins {
|
||||||
pluginsList := maps.Keys(staticConfiguration.Experimental.Plugins)
|
pluginsList := slices.Collect(maps.Keys(staticConfiguration.Experimental.Plugins))
|
||||||
pluginsList = append(pluginsList, maps.Keys(staticConfiguration.Experimental.LocalPlugins)...)
|
pluginsList = append(pluginsList, slices.Collect(maps.Keys(staticConfiguration.Experimental.LocalPlugins))...)
|
||||||
|
|
||||||
pluginLogger = pluginLogger.With().Strs("plugins", pluginsList).Logger()
|
pluginLogger = pluginLogger.With().Strs("plugins", pluginsList).Logger()
|
||||||
pluginLogger.Info().Msg("Loading plugins...")
|
pluginLogger.Info().Msg("Loading plugins...")
|
||||||
@ -427,7 +427,7 @@ func getDefaultsEntrypoints(staticConfiguration *static.Configuration) []string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(defaultEntryPoints)
|
slices.Sort(defaultEntryPoints)
|
||||||
return defaultEntryPoints
|
return defaultEntryPoints
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,7 +568,7 @@ func registerMetricClients(metricsConfig *types.Metrics) []metrics.Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func appendCertMetric(gauge gokitmetrics.Gauge, certificate *x509.Certificate) {
|
func appendCertMetric(gauge gokitmetrics.Gauge, certificate *x509.Certificate) {
|
||||||
sort.Strings(certificate.DNSNames)
|
slices.Sort(certificate.DNSNames)
|
||||||
|
|
||||||
labels := []string{
|
labels := []string{
|
||||||
"cn", certificate.Subject.CommonName,
|
"cn", certificate.Subject.CommonName,
|
||||||
|
2
go.mod
2
go.mod
@ -88,7 +88,6 @@ require (
|
|||||||
go.opentelemetry.io/otel/sdk/log v0.8.0
|
go.opentelemetry.io/otel/sdk/log v0.8.0
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.28.0
|
go.opentelemetry.io/otel/sdk/metric v1.28.0
|
||||||
go.opentelemetry.io/otel/trace v1.32.0
|
go.opentelemetry.io/otel/trace v1.32.0
|
||||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // No tag on the repo.
|
|
||||||
golang.org/x/mod v0.21.0
|
golang.org/x/mod v0.21.0
|
||||||
golang.org/x/net v0.30.0
|
golang.org/x/net v0.30.0
|
||||||
golang.org/x/sync v0.10.0
|
golang.org/x/sync v0.10.0
|
||||||
@ -365,6 +364,7 @@ require (
|
|||||||
go.uber.org/zap v1.26.0 // indirect
|
go.uber.org/zap v1.26.0 // indirect
|
||||||
golang.org/x/arch v0.4.0 // indirect
|
golang.org/x/arch v0.4.0 // indirect
|
||||||
golang.org/x/crypto v0.31.0 // indirect
|
golang.org/x/crypto v0.31.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
||||||
golang.org/x/oauth2 v0.23.0 // indirect
|
golang.org/x/oauth2 v0.23.0 // indirect
|
||||||
golang.org/x/term v0.27.0 // indirect
|
golang.org/x/term v0.27.0 // indirect
|
||||||
google.golang.org/api v0.204.0 // indirect
|
google.golang.org/api v0.204.0 // indirect
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -357,7 +356,7 @@ func sortByName[T orderedWithName](direction string, results []T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortByFunc[T orderedWithName, U constraints.Ordered](direction string, results []T, fn func(int) U) {
|
func sortByFunc[T orderedWithName, U cmp.Ordered](direction string, results []T, fn func(int) U) {
|
||||||
// Ascending
|
// Ascending
|
||||||
if direction == ascendantSorting {
|
if direction == ascendantSorting {
|
||||||
sort.Slice(results, func(i, j int) bool {
|
sort.Slice(results, func(i, j int) bool {
|
||||||
|
@ -4,13 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/traefik/traefik/v3/pkg/ip"
|
"github.com/traefik/traefik/v3/pkg/ip"
|
||||||
"github.com/traefik/traefik/v3/pkg/middlewares/requestdecorator"
|
"github.com/traefik/traefik/v3/pkg/middlewares/requestdecorator"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpFuncs = map[string]func(*matchersTree, ...string) error{
|
var httpFuncs = map[string]func(*matchersTree, ...string) error{
|
||||||
|
@ -3,8 +3,9 @@ package provider
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"maps"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"unicode"
|
"unicode"
|
||||||
@ -14,7 +15,6 @@ import (
|
|||||||
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
||||||
"github.com/traefik/traefik/v3/pkg/logs"
|
"github.com/traefik/traefik/v3/pkg/logs"
|
||||||
"github.com/traefik/traefik/v3/pkg/tls"
|
"github.com/traefik/traefik/v3/pkg/tls"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Merge merges multiple configurations.
|
// Merge merges multiple configurations.
|
||||||
@ -80,7 +80,7 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration
|
|||||||
for key := range configurations {
|
for key := range configurations {
|
||||||
sortedKeys = append(sortedKeys, key)
|
sortedKeys = append(sortedKeys, key)
|
||||||
}
|
}
|
||||||
sort.Strings(sortedKeys)
|
slices.Sort(sortedKeys)
|
||||||
|
|
||||||
for _, root := range sortedKeys {
|
for _, root := range sortedKeys {
|
||||||
conf := configurations[root]
|
conf := configurations[root]
|
||||||
@ -423,7 +423,7 @@ func BuildTCPRouterConfiguration(ctx context.Context, configuration *dynamic.TCP
|
|||||||
if len(configuration.Services) > 1 {
|
if len(configuration.Services) > 1 {
|
||||||
delete(configuration.Routers, routerName)
|
delete(configuration.Routers, routerName)
|
||||||
loggerRouter.Error().
|
loggerRouter.Error().
|
||||||
Msgf("Router %s cannot be linked automatically with multiple Services: %q", routerName, maps.Keys(configuration.Services))
|
Msgf("Router %s cannot be linked automatically with multiple Services: %q", routerName, slices.Collect(maps.Keys(configuration.Services)))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ func BuildUDPRouterConfiguration(ctx context.Context, configuration *dynamic.UDP
|
|||||||
if len(configuration.Services) > 1 {
|
if len(configuration.Services) > 1 {
|
||||||
delete(configuration.Routers, routerName)
|
delete(configuration.Routers, routerName)
|
||||||
loggerRouter.Error().
|
loggerRouter.Error().
|
||||||
Msgf("Router %s cannot be linked automatically with multiple Services: %q", routerName, maps.Keys(configuration.Services))
|
Msgf("Router %s cannot be linked automatically with multiple Services: %q", routerName, slices.Collect(maps.Keys(configuration.Services)))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,7 +494,7 @@ func BuildRouterConfiguration(ctx context.Context, configuration *dynamic.HTTPCo
|
|||||||
if len(configuration.Services) > 1 {
|
if len(configuration.Services) > 1 {
|
||||||
delete(configuration.Routers, routerName)
|
delete(configuration.Routers, routerName)
|
||||||
loggerRouter.Error().
|
loggerRouter.Error().
|
||||||
Msgf("Router %s cannot be linked automatically with multiple Services: %q", routerName, maps.Keys(configuration.Services))
|
Msgf("Router %s cannot be linked automatically with multiple Services: %q", routerName, slices.Collect(maps.Keys(configuration.Services)))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user