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

@@ -20,4 +20,4 @@ jobs:
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with: with:
version: v2.7.2 version: v2.9.0

View File

@@ -1 +1 @@
1.25.7 1.26.0

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. // All returns all RRs from e, regardless of type.
func (e *Elem) All() []dns.RR { func (e *Elem) All() []dns.RR {
list := []dns.RR{} list := make([]dns.RR, 0, len(e.m))
for _, rrs := range e.m { for _, rrs := range e.m {
list = append(list, rrs...) 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 poolLen := uint32(len(p)) // #nosec G115 -- pool length is small
i := atomic.AddUint32(&r.robin, 1) % poolLen 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]...)
robin = append(robin, p[i+1:]...) 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 poolLen := uint32(len(p)) // #nosec G115 -- pool length is small
i := atomic.AddUint32(&r.robin, 1) % poolLen 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]...)
robin = append(robin, p[i+1:]...) robin = append(robin, p[i+1:]...)

View File

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

View File

@@ -38,7 +38,7 @@ func TestTransferAXFR(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) 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 { for rrs := range ch {
records = append(records, rrs...) records = append(records, rrs...)
} }
@@ -104,7 +104,7 @@ func TestTransferIXFR(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) 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 { for rrs := range ch {
records = append(records, rrs...) records = append(records, rrs...)
} }

View File

@@ -105,7 +105,7 @@ func (external) EpIndex(s string) []*object.Endpoints {
} }
func (external) EndpointsList() []*object.Endpoints { func (external) EndpointsList() []*object.Endpoints {
var eps []*object.Endpoints eps := make([]*object.Endpoints, 0, len(epIndexExternal))
for _, ep := range epIndexExternal { for _, ep := range epIndexExternal {
eps = append(eps, ep...) eps = append(eps, ep...)
} }
@@ -189,7 +189,7 @@ var svcIndexExternal = map[string][]*object.Service{
} }
func (external) ServiceList() []*object.Service { func (external) ServiceList() []*object.Service {
var svcs []*object.Service svcs := make([]*object.Service, 0, len(svcIndexExternal))
for _, svc := range svcIndexExternal { for _, svc := range svcIndexExternal {
svcs = append(svcs, svc...) 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) SvcIndex(s string) []*object.Service { return svcIndex[s] }
func (APIConnServeTest) ServiceList() []*object.Service { func (APIConnServeTest) ServiceList() []*object.Service {
var svcs []*object.Service svcs := make([]*object.Service, 0, len(svcIndex))
for _, svc := range svcIndex { for _, svc := range svcIndex {
svcs = append(svcs, svc...) 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) SvcImportIndex(s string) []*object.ServiceImport { return svcImportIndex[s] }
func (APIConnServeTest) ServiceImportList() []*object.ServiceImport { func (APIConnServeTest) ServiceImportList() []*object.ServiceImport {
var svcs []*object.ServiceImport svcs := make([]*object.ServiceImport, 0, len(svcImportIndex))
for _, svc := range svcImportIndex { for _, svc := range svcImportIndex {
svcs = append(svcs, svc...) svcs = append(svcs, svc...)
} }
@@ -1118,7 +1118,7 @@ func (APIConnServeTest) McEpIndex(s string) []*object.MultiClusterEndpoints {
} }
func (APIConnServeTest) MultiClusterEndpointsList() []*object.MultiClusterEndpoints { func (APIConnServeTest) MultiClusterEndpointsList() []*object.MultiClusterEndpoints {
var eps []*object.MultiClusterEndpoints eps := make([]*object.MultiClusterEndpoints, 0, len(mcEpsIndex))
for _, ep := range mcEpsIndex { for _, ep := range mcEpsIndex {
eps = append(eps, ep...) eps = append(eps, ep...)
} }
@@ -1126,7 +1126,7 @@ func (APIConnServeTest) MultiClusterEndpointsList() []*object.MultiClusterEndpoi
} }
func (APIConnServeTest) EndpointsList() []*object.Endpoints { func (APIConnServeTest) EndpointsList() []*object.Endpoints {
var eps []*object.Endpoints eps := make([]*object.Endpoints, 0, len(epsIndex))
for _, ep := range epsIndex { for _, ep := range epsIndex {
eps = append(eps, ep...) eps = append(eps, ep...)
} }

View File

@@ -88,7 +88,7 @@ func TestKubernetesIXFRCurrent(t *testing.T) {
t.Error(err) t.Error(err)
} }
var gotRRs []dns.RR var gotRRs []dns.RR //nolint:prealloc // records are read from a channel
for rrs := range ch { for rrs := range ch {
gotRRs = append(gotRRs, rrs...) 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."), 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"} 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 { for _, cidr := range cidrs {
_, subnet, err := net.ParseCIDR(cidr) _, subnet, err := net.ParseCIDR(cidr)
if err != nil { 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" }}, {"test/key2": func() string { return "two" }, "test/key3": func() string { return "testvalue3" }},
} }
// Create fake Providers based on expectedMetadata // Create fake Providers based on expectedMetadata
providers := []Provider{} providers := make([]Provider, 0, len(expectedMetadata))
for _, e := range expectedMetadata { for _, e := range expectedMetadata {
providers = append(providers, e) providers = append(providers, e)
} }

View File

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

View File

@@ -60,7 +60,7 @@ func reverse6(slice []string) string {
j := len(slice) - i - 1 j := len(slice) - i - 1
slice[i], slice[j] = slice[j], slice[i] slice[i], slice[j] = slice[j], slice[i]
} }
slice6 := []string{} slice6 := make([]string, 0, len(slice)/4)
for i := range len(slice) / 4 { for i := range len(slice) / 4 {
slice6 = append(slice6, strings.Join(slice[i*4:i*4+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. // setZones will set zones in f.
func (f *F) setZones(zones []string) { func (f *F) setZones(zones []string) {
z := []string{} z := make([]string, 0, len(zones))
for i := range zones { for i := range zones {
z = append(z, plugin.Host(zones[i]).NormalizeExact()...) 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 // and in case of filename a resolv.conf like file is (assumed) and parsed and
// the nameservers found are returned. // the nameservers found are returned.
func HostPortOrFile(s ...string) ([]string, error) { 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 { for _, h := range s {
trans, host := Transport(h) trans, host := Transport(h)
if len(host) == 0 { 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) { func TestCNameTargetRewrite(t *testing.T) {
rules := []Rule{}
ruleset := []struct { ruleset := []struct {
args []string args []string
expectedType reflect.Type 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", "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]()}, {[]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 { for i, r := range ruleset {
rule, err := newRule(r.args...) rule, err := newRule(r.args...)
if err != nil { if err != nil {

View File

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

View File

@@ -191,7 +191,7 @@ func TestNewRule(t *testing.T) {
} }
func TestRewriteDefaultRevertPolicy(t *testing.T) { func TestRewriteDefaultRevertPolicy(t *testing.T) {
rules := []Rule{} rules := make([]Rule, 0, 4)
r, _ := newNameRule("stop", "prefix", "prefix", "to") r, _ := newNameRule("stop", "prefix", "prefix", "to")
rules = append(rules, r) rules = append(rules, r)
@@ -244,7 +244,7 @@ func TestRewriteDefaultRevertPolicy(t *testing.T) {
} }
func TestRewrite(t *testing.T) { func TestRewrite(t *testing.T) {
rules := []Rule{} rules := make([]Rule, 0, 12)
r, _ := newNameRule("stop", "from.nl.", "to.nl.") r, _ := newNameRule("stop", "from.nl.", "to.nl.")
rules = append(rules, r) 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}") 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) { func TestTtlRewrite(t *testing.T) {
rules := []Rule{}
ruleset := []struct { ruleset := []struct {
args []string args []string
expectedType reflect.Type 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", "ceil.example.com.", "-11"}, reflect.TypeFor[*exactTTLRule]()},
{[]string{"stop", "ttl", "floor.example.com.", "5-"}, reflect.TypeFor[*exactTTLRule]()}, {[]string{"stop", "ttl", "floor.example.com.", "5-"}, reflect.TypeFor[*exactTTLRule]()},
} }
rules := make([]Rule, 0, len(ruleset))
for i, r := range ruleset { for i, r := range ruleset {
rule, err := newRule(r.args...) rule, err := newRule(r.args...)
if err != nil { if err != nil {