chore: bump Go version to 1.26.0 (#7856)

This commit is contained in:
Ville Vesilehto
2026-02-16 14:26:18 +02:00
committed by GitHub
parent 0f0a9920b1
commit b1080a2934
20 changed files with 34 additions and 32 deletions

View File

@@ -49,7 +49,7 @@ func (e *Elem) TypeForWildcard(qtype uint16, qname string) []dns.RR {
// All returns all RRs from e, regardless of type.
func (e *Elem) All() []dns.RR {
list := []dns.RR{}
list := make([]dns.RR, 0, len(e.m))
for _, rrs := range e.m {
list = append(list, rrs...)
}

View File

@@ -50,7 +50,8 @@ func (r *roundRobin) List(p []*proxy.Proxy) []*proxy.Proxy {
poolLen := uint32(len(p)) // #nosec G115 -- pool length is small
i := atomic.AddUint32(&r.robin, 1) % poolLen
robin := []*proxy.Proxy{p[i]}
robin := make([]*proxy.Proxy, 0, len(p))
robin = append(robin, p[i])
robin = append(robin, p[:i]...)
robin = append(robin, p[i+1:]...)

View File

@@ -54,7 +54,8 @@ func (r *roundRobin) List(p []*Proxy) []*Proxy {
poolLen := uint32(len(p)) // #nosec G115 -- pool length is small
i := atomic.AddUint32(&r.robin, 1) % poolLen
robin := []*Proxy{p[i]}
robin := make([]*Proxy, 0, len(p))
robin = append(robin, p[i])
robin = append(robin, p[:i]...)
robin = append(robin, p[i+1:]...)

View File

@@ -298,7 +298,7 @@ func (external) EpIndex(s string) []*object.Endpoints {
}
func (external) EndpointsList() []*object.Endpoints {
var eps []*object.Endpoints
eps := make([]*object.Endpoints, 0, len(epIndexExternal))
for _, ep := range epIndexExternal {
eps = append(eps, ep...)
}
@@ -416,7 +416,7 @@ var svcIndexExternal = map[string][]*object.Service{
}
func (external) ServiceList() []*object.Service {
var svcs []*object.Service
svcs := make([]*object.Service, 0, len(svcIndexExternal))
for _, svc := range svcIndexExternal {
svcs = append(svcs, svc...)
}

View File

@@ -38,7 +38,7 @@ func TestTransferAXFR(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
var records []dns.RR
var records []dns.RR //nolint:prealloc // records are read from a channel
for rrs := range ch {
records = append(records, rrs...)
}
@@ -104,7 +104,7 @@ func TestTransferIXFR(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
var records []dns.RR
var records []dns.RR //nolint:prealloc // records are read from a channel
for rrs := range ch {
records = append(records, rrs...)
}

View File

@@ -105,7 +105,7 @@ func (external) EpIndex(s string) []*object.Endpoints {
}
func (external) EndpointsList() []*object.Endpoints {
var eps []*object.Endpoints
eps := make([]*object.Endpoints, 0, len(epIndexExternal))
for _, ep := range epIndexExternal {
eps = append(eps, ep...)
}
@@ -189,7 +189,7 @@ var svcIndexExternal = map[string][]*object.Service{
}
func (external) ServiceList() []*object.Service {
var svcs []*object.Service
svcs := make([]*object.Service, 0, len(svcIndexExternal))
for _, svc := range svcIndexExternal {
svcs = append(svcs, svc...)
}

View File

@@ -835,7 +835,7 @@ var svcIndex = map[string][]*object.Service{
func (APIConnServeTest) SvcIndex(s string) []*object.Service { return svcIndex[s] }
func (APIConnServeTest) ServiceList() []*object.Service {
var svcs []*object.Service
svcs := make([]*object.Service, 0, len(svcIndex))
for _, svc := range svcIndex {
svcs = append(svcs, svc...)
}
@@ -1012,7 +1012,7 @@ var svcImportIndex = map[string][]*object.ServiceImport{
func (APIConnServeTest) SvcImportIndex(s string) []*object.ServiceImport { return svcImportIndex[s] }
func (APIConnServeTest) ServiceImportList() []*object.ServiceImport {
var svcs []*object.ServiceImport
svcs := make([]*object.ServiceImport, 0, len(svcImportIndex))
for _, svc := range svcImportIndex {
svcs = append(svcs, svc...)
}
@@ -1118,7 +1118,7 @@ func (APIConnServeTest) McEpIndex(s string) []*object.MultiClusterEndpoints {
}
func (APIConnServeTest) MultiClusterEndpointsList() []*object.MultiClusterEndpoints {
var eps []*object.MultiClusterEndpoints
eps := make([]*object.MultiClusterEndpoints, 0, len(mcEpsIndex))
for _, ep := range mcEpsIndex {
eps = append(eps, ep...)
}
@@ -1126,7 +1126,7 @@ func (APIConnServeTest) MultiClusterEndpointsList() []*object.MultiClusterEndpoi
}
func (APIConnServeTest) EndpointsList() []*object.Endpoints {
var eps []*object.Endpoints
eps := make([]*object.Endpoints, 0, len(epsIndex))
for _, ep := range epsIndex {
eps = append(eps, ep...)
}

View File

@@ -88,7 +88,7 @@ func TestKubernetesIXFRCurrent(t *testing.T) {
t.Error(err)
}
var gotRRs []dns.RR
var gotRRs []dns.RR //nolint:prealloc // records are read from a channel
for rrs := range ch {
gotRRs = append(gotRRs, rrs...)
}

View File

@@ -23,8 +23,8 @@ func TestSortPreferred(t *testing.T) {
test.CNAME("example.org. 300 IN CNAME alias.example.org."),
}
subnets := []*net.IPNet{}
cidrs := []string{"2001:db8::/32", "10.9.20.0/24", "10.9.30.0/24"}
subnets := make([]*net.IPNet, 0, len(cidrs))
for _, cidr := range cidrs {
_, subnet, err := net.ParseCIDR(cidr)
if err != nil {

View File

@@ -34,7 +34,7 @@ func TestMetadataServeDNS(t *testing.T) {
{"test/key2": func() string { return "two" }, "test/key3": func() string { return "testvalue3" }},
}
// Create fake Providers based on expectedMetadata
providers := []Provider{}
providers := make([]Provider, 0, len(expectedMetadata))
for _, e := range expectedMetadata {
providers = append(providers, e)
}

View File

@@ -142,7 +142,7 @@ func (m *Metrics) stopServer() error {
func (m *Metrics) OnFinalShutdown() error { return m.stopServer() }
func keys(m map[string]struct{}) []string {
sx := []string{}
sx := make([]string, 0, len(m))
for k := range m {
sx = append(sx, k)
}

View File

@@ -60,7 +60,7 @@ func reverse6(slice []string) string {
j := len(slice) - i - 1
slice[i], slice[j] = slice[j], slice[i]
}
slice6 := []string{}
slice6 := make([]string, 0, len(slice)/4)
for i := range len(slice) / 4 {
slice6 = append(slice6, strings.Join(slice[i*4:i*4+4], ""))
}

View File

@@ -32,7 +32,7 @@ func (f F) Through(qname string) bool {
// setZones will set zones in f.
func (f *F) setZones(zones []string) {
z := []string{}
z := make([]string, 0, len(zones))
for i := range zones {
z = append(z, plugin.Host(zones[i]).NormalizeExact()...)
}

View File

@@ -30,7 +30,7 @@ func stripZone(host string) string {
// and in case of filename a resolv.conf like file is (assumed) and parsed and
// the nameservers found are returned.
func HostPortOrFile(s ...string) ([]string, error) {
var servers []string //nolint:prealloc // impossible to know the final length upfront
var servers []string
for _, h := range s {
trans, host := Transport(h)
if len(host) == 0 {

View File

@@ -66,7 +66,6 @@ func (u *MockedUpstream) Lookup(ctx context.Context, state request.Request, name
}
func TestCNameTargetRewrite(t *testing.T) {
rules := []Rule{}
ruleset := []struct {
args []string
expectedType reflect.Type
@@ -78,6 +77,7 @@ func TestCNameTargetRewrite(t *testing.T) {
{[]string{"continue", "cname", "regex", `(.*)\.web\.(.*)\.site\.`, `{1}.webapp.{2}.org.`}, reflect.TypeFor[*cnameTargetRule]()},
{[]string{"continue", "cname", "exact", "music.truncated.spotify.com.", "music.truncated.spotify.com."}, reflect.TypeFor[*cnameTargetRule]()},
}
rules := make([]Rule, 0, len(ruleset))
for i, r := range ruleset {
rule, err := newRule(r.args...)
if err != nil {

View File

@@ -31,13 +31,13 @@ var tests = []struct {
}
func TestResponseReverter(t *testing.T) {
rules := []Rule{}
rules := make([]Rule, 0, 1)
r, _ := newNameRule("stop", "regex", `(core)\.(dns)\.(rocks)`, "{2}.{1}.{3}", "answer", "name", `(dns)\.(core)\.(rocks)`, "{2}.{1}.{3}")
rules = append(rules, r)
doReverterTests(t, rules)
rules = []Rule{}
rules = make([]Rule, 0, 1)
r, _ = newNameRule("continue", "regex", `(core)\.(dns)\.(rocks)`, "{2}.{1}.{3}", "answer", "name", `(dns)\.(core)\.(rocks)`, "{2}.{1}.{3}")
rules = append(rules, r)
@@ -98,7 +98,7 @@ var valueTests = []struct {
}
func TestValueResponseReverter(t *testing.T) {
rules := []Rule{}
rules := make([]Rule, 0, 1)
r, err := newNameRule("stop", "regex", `(.*)\.domain\.uk`, "{1}.cluster.local", "answer", "name", `(.*)\.cluster\.local`, "{1}.domain.uk", "answer", "value", `(.*)\.cluster\.local`, "{1}.domain.uk")
if err != nil {
t.Errorf("cannot parse rule: %s", err)
@@ -108,7 +108,7 @@ func TestValueResponseReverter(t *testing.T) {
doValueReverterTests(t, "stop", rules)
rules = []Rule{}
rules = make([]Rule, 0, 1)
r, err = newNameRule("continue", "regex", `(.*)\.domain\.uk`, "{1}.cluster.local", "answer", "name", `(.*)\.cluster\.local`, "{1}.domain.uk", "answer", "value", `(.*)\.cluster\.local`, "{1}.domain.uk")
if err != nil {
t.Errorf("cannot parse rule: %s", err)
@@ -118,7 +118,7 @@ func TestValueResponseReverter(t *testing.T) {
doValueReverterTests(t, "continue", rules)
rules = []Rule{}
rules = make([]Rule, 0, 1)
r, err = newNameRule("stop", "suffix", `.domain.uk`, ".cluster.local", "answer", "auto", "answer", "value", `(.*)\.cluster\.local`, "{1}.domain.uk")
if err != nil {
t.Errorf("cannot parse rule: %s", err)
@@ -129,7 +129,7 @@ func TestValueResponseReverter(t *testing.T) {
doValueReverterTests(t, "suffix", rules)
// multiple rules
rules = []Rule{}
rules = make([]Rule, 0, 1)
r, err = newNameRule("continue", "suffix", `.domain.uk`, ".domain.us", "answer", "auto")
if err != nil {
t.Errorf("cannot parse rule: %s", err)

View File

@@ -191,7 +191,7 @@ func TestNewRule(t *testing.T) {
}
func TestRewriteDefaultRevertPolicy(t *testing.T) {
rules := []Rule{}
rules := make([]Rule, 0, 4)
r, _ := newNameRule("stop", "prefix", "prefix", "to")
rules = append(rules, r)
@@ -244,7 +244,7 @@ func TestRewriteDefaultRevertPolicy(t *testing.T) {
}
func TestRewrite(t *testing.T) {
rules := []Rule{}
rules := make([]Rule, 0, 12)
r, _ := newNameRule("stop", "from.nl.", "to.nl.")
rules = append(rules, r)
r, _ = newNameRule("stop", "regex", "(core)\\.(dns)\\.(rocks)\\.(nl)", "{2}.{1}.{3}.{4}", "answer", "name", "(dns)\\.(core)\\.(rocks)\\.(nl)", "{2}.{1}.{3}.{4}")

View File

@@ -74,7 +74,6 @@ func TestNewTTLRule(t *testing.T) {
}
func TestTtlRewrite(t *testing.T) {
rules := []Rule{}
ruleset := []struct {
args []string
expectedType reflect.Type
@@ -90,6 +89,7 @@ func TestTtlRewrite(t *testing.T) {
{[]string{"stop", "ttl", "ceil.example.com.", "-11"}, reflect.TypeFor[*exactTTLRule]()},
{[]string{"stop", "ttl", "floor.example.com.", "5-"}, reflect.TypeFor[*exactTTLRule]()},
}
rules := make([]Rule, 0, len(ruleset))
for i, r := range ruleset {
rule, err := newRule(r.args...)
if err != nil {