chore: Upgrade to golangci-lint v2 (#7236)

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
Manuel Rüger
2025-04-04 20:27:39 +02:00
committed by GitHub
parent e16162dd3c
commit 76ba39ffe9
50 changed files with 240 additions and 219 deletions

View File

@@ -54,9 +54,9 @@ func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
}
a.Zones.RLock()
z, ok := a.Zones.Z[zone]
a.Zones.RUnlock()
a.RLock()
z, ok := a.Z[zone]
a.RUnlock()
if !ok || z == nil {
return dns.RcodeServerFailure, nil

View File

@@ -48,11 +48,11 @@ func setup(c *caddy.Controller) error {
if err := a.Notify(); err != nil {
log.Warning(err)
}
if a.loader.ReloadInterval == 0 {
if a.ReloadInterval == 0 {
return nil
}
go func() {
ticker := time.NewTicker(a.loader.ReloadInterval)
ticker := time.NewTicker(a.ReloadInterval)
defer ticker.Stop()
for {
select {
@@ -71,7 +71,7 @@ func setup(c *caddy.Controller) error {
c.OnShutdown(func() error {
close(walkChan)
for _, z := range a.Zones.Z {
for _, z := range a.Z {
z.Lock()
z.OnShutdown()
z.Unlock()
@@ -103,8 +103,8 @@ func autoParse(c *caddy.Controller) (Auto, error) {
for c.Next() {
// auto [ZONES...]
args := c.RemainingArgs()
a.Zones.origins = plugin.OriginsFromArgsOrServerBlock(args, c.ServerBlockKeys)
a.loader.upstream = upstream.New()
a.origins = plugin.OriginsFromArgsOrServerBlock(args, c.ServerBlockKeys)
a.upstream = upstream.New()
for c.NextBlock() {
switch c.Val() {
@@ -112,33 +112,33 @@ func autoParse(c *caddy.Controller) (Auto, error) {
if !c.NextArg() {
return a, c.ArgErr()
}
a.loader.directory = c.Val()
if !filepath.IsAbs(a.loader.directory) && config.Root != "" {
a.loader.directory = filepath.Join(config.Root, a.loader.directory)
a.directory = c.Val()
if !filepath.IsAbs(a.directory) && config.Root != "" {
a.directory = filepath.Join(config.Root, a.directory)
}
_, err := os.Stat(a.loader.directory)
_, err := os.Stat(a.directory)
if err != nil {
if os.IsNotExist(err) {
log.Warningf("Directory does not exist: %s", a.loader.directory)
log.Warningf("Directory does not exist: %s", a.directory)
} else {
return a, c.Errf("Unable to access root path '%s': %v", a.loader.directory, err)
return a, c.Errf("Unable to access root path '%s': %v", a.directory, err)
}
}
// regexp template
if c.NextArg() {
a.loader.re, err = regexp.Compile(c.Val())
a.re, err = regexp.Compile(c.Val())
if err != nil {
return a, err
}
if a.loader.re.NumSubexp() == 0 {
if a.re.NumSubexp() == 0 {
return a, c.Errf("Need at least one sub expression")
}
if !c.NextArg() {
return a, c.ArgErr()
}
a.loader.template = rewriteToExpand(c.Val())
a.template = rewriteToExpand(c.Val())
}
if c.NextArg() {
@@ -157,7 +157,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
if err != nil {
return a, plugin.Error("file", err)
}
a.loader.ReloadInterval = d
a.ReloadInterval = d
case "upstream":
// remove soon
@@ -169,8 +169,8 @@ func autoParse(c *caddy.Controller) (Auto, error) {
}
}
if a.loader.ReloadInterval == nilInterval {
a.loader.ReloadInterval = 60 * time.Second
if a.ReloadInterval == nilInterval {
a.ReloadInterval = 60 * time.Second
}
return a, nil

View File

@@ -111,17 +111,17 @@ func TestAutoParse(t *testing.T) {
} else if err != nil && !test.shouldErr {
t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
} else if !test.shouldErr {
if a.loader.directory != test.expectedDirectory {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedDirectory, a.loader.directory)
if a.directory != test.expectedDirectory {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedDirectory, a.directory)
}
if a.loader.template != test.expectedTempl {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedTempl, a.loader.template)
if a.template != test.expectedTempl {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedTempl, a.template)
}
if a.loader.re.String() != test.expectedRe {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedRe, a.loader.re)
if a.re.String() != test.expectedRe {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedRe, a.re)
}
if a.loader.ReloadInterval != test.expectedReloadInterval {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedReloadInterval, a.loader.ReloadInterval)
if a.ReloadInterval != test.expectedReloadInterval {
t.Fatalf("Test %d expected %v, got %v", i, test.expectedReloadInterval, a.ReloadInterval)
}
}
}

View File

@@ -15,11 +15,11 @@ func (a Auto) Walk() error {
// TODO(miek): should add something so that we don't stomp on each other.
toDelete := make(map[string]bool)
for _, n := range a.Zones.Names() {
for _, n := range a.Names() {
toDelete[n] = true
}
filepath.Walk(a.loader.directory, func(path string, info os.FileInfo, e error) error {
filepath.Walk(a.directory, func(path string, info os.FileInfo, e error) error {
if e != nil {
log.Warningf("error reading %v: %v", path, e)
}
@@ -27,12 +27,12 @@ func (a Auto) Walk() error {
return nil
}
match, origin := matches(a.loader.re, info.Name(), a.loader.template)
match, origin := matches(a.re, info.Name(), a.template)
if !match {
return nil
}
if z, ok := a.Zones.Z[origin]; ok {
if z, ok := a.Z[origin]; ok {
// we already have this zone
toDelete[origin] = false
z.SetFile(path)
@@ -53,10 +53,10 @@ func (a Auto) Walk() error {
return nil
}
zo.ReloadInterval = a.loader.ReloadInterval
zo.Upstream = a.loader.upstream
zo.ReloadInterval = a.ReloadInterval
zo.Upstream = a.upstream
a.Zones.Add(zo, origin, a.transfer)
a.Add(zo, origin, a.transfer)
if a.metrics != nil {
a.metrics.AddZone(origin)
@@ -78,7 +78,7 @@ func (a Auto) Walk() error {
a.metrics.RemoveZone(origin)
}
a.Zones.Remove(origin)
a.Remove(origin)
log.Infof("Deleting zone `%s'", origin)
}

View File

@@ -38,7 +38,7 @@ func TestWalk(t *testing.T) {
// db.example.org and db.example.com should be here (created in createFiles)
for _, name := range []string{"example.com.", "example.org."} {
if _, ok := a.Zones.Z[name]; !ok {
if _, ok := a.Z[name]; !ok {
t.Errorf("%s should have been added", name)
}
}

View File

@@ -27,10 +27,10 @@ func TestWatcher(t *testing.T) {
a.Walk()
// example.org and example.com should exist, we have 3 apex rrs and 1 "real" record. All() returns the non-apex ones.
if x := len(a.Zones.Z["example.org."].All()); x != 1 {
if x := len(a.Z["example.org."].All()); x != 1 {
t.Fatalf("Expected 1 RRs, got %d", x)
}
if x := len(a.Zones.Z["example.com."].All()); x != 1 {
if x := len(a.Z["example.com."].All()); x != 1 {
t.Fatalf("Expected 1 RRs, got %d", x)
}
@@ -41,10 +41,10 @@ func TestWatcher(t *testing.T) {
a.Walk()
if _, ok := a.Zones.Z["example.com."]; ok {
if _, ok := a.Z["example.com."]; ok {
t.Errorf("Expected %q to be gone.", "example.com.")
}
if _, ok := a.Zones.Z["example.org."]; !ok {
if _, ok := a.Z["example.org."]; !ok {
t.Errorf("Expected %q to still be there.", "example.org.")
}
}
@@ -83,7 +83,7 @@ func TestSymlinks(t *testing.T) {
a.Walk()
if storedZone, ok := a.Zones.Z["example.com."]; ok {
if storedZone, ok := a.Z["example.com."]; ok {
storedFile := storedZone.File()
if storedFile != newFile {
t.Errorf("Expected %q to reflect new path %q", storedFile, newFile)

View File

@@ -8,9 +8,9 @@ import (
// Transfer implements the transfer.Transfer interface.
func (a Auto) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
a.Zones.RLock()
z, ok := a.Zones.Z[zone]
a.Zones.RUnlock()
a.RLock()
z, ok := a.Z[zone]
a.RUnlock()
if !ok || z == nil {
return nil, transfer.ErrNotAuthoritative
@@ -21,7 +21,7 @@ func (a Auto) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
// Notify sends notifies for all zones with secondaries configured with the transfer plugin
func (a Auto) Notify() error {
var err error
for _, origin := range a.Zones.Names() {
for _, origin := range a.Names() {
e := a.transfer.Notify(origin)
if e != nil {
err = e