mirror of
https://github.com/coredns/coredns.git
synced 2025-11-29 23:24:26 -05:00
chore: Upgrade to golangci-lint v2 (#7236)
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
7
plugin/cache/cache.go
vendored
7
plugin/cache/cache.go
vendored
@@ -189,11 +189,12 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||
|
||||
msgTTL := dnsutil.MinimalTTL(res, mt)
|
||||
var duration time.Duration
|
||||
if mt == response.NameError || mt == response.NoData {
|
||||
switch mt {
|
||||
case response.NameError, response.NoData:
|
||||
duration = computeTTL(msgTTL, w.minnttl, w.nttl)
|
||||
} else if mt == response.ServerError {
|
||||
case response.ServerError:
|
||||
duration = w.failttl
|
||||
} else {
|
||||
default:
|
||||
duration = computeTTL(msgTTL, w.minpttl, w.pttl)
|
||||
}
|
||||
|
||||
|
||||
18
plugin/cache/cache_test.go
vendored
18
plugin/cache/cache_test.go
vendored
@@ -467,14 +467,15 @@ func TestServeFromStaleCacheFetchVerify(t *testing.T) {
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
c.now = func() time.Time { return time.Now().Add(time.Duration(tt.futureMinutes) * time.Minute) }
|
||||
|
||||
if tt.upstreamRCode == dns.RcodeSuccess {
|
||||
switch tt.upstreamRCode {
|
||||
case dns.RcodeSuccess:
|
||||
c.Next = ttlBackend(tt.upstreamTtl)
|
||||
} else if tt.upstreamRCode == dns.RcodeServerFailure {
|
||||
case dns.RcodeServerFailure:
|
||||
// Make upstream fail, should now rely on cache during the c.staleUpTo period
|
||||
c.Next = servFailBackend(tt.upstreamTtl)
|
||||
} else if tt.upstreamRCode == dns.RcodeNameError {
|
||||
case dns.RcodeNameError:
|
||||
c.Next = nxDomainBackend(tt.upstreamTtl)
|
||||
} else {
|
||||
default:
|
||||
t.Fatal("upstream code not implemented")
|
||||
}
|
||||
|
||||
@@ -485,12 +486,13 @@ func TestServeFromStaleCacheFetchVerify(t *testing.T) {
|
||||
t.Errorf("Test %d: expected rcode=%v, got rcode=%v", i, tt.expectedRCode, ret)
|
||||
continue
|
||||
}
|
||||
if ret == dns.RcodeSuccess {
|
||||
switch ret {
|
||||
case dns.RcodeSuccess:
|
||||
recTtl := rec.Msg.Answer[0].Header().Ttl
|
||||
if tt.expectedTtl != int(recTtl) {
|
||||
t.Errorf("Test %d: expected TTL=%d, got TTL=%d", i, tt.expectedTtl, recTtl)
|
||||
}
|
||||
} else if ret == dns.RcodeNameError {
|
||||
case dns.RcodeNameError:
|
||||
soaTtl := rec.Msg.Ns[0].Header().Ttl
|
||||
if tt.expectedTtl != int(soaTtl) {
|
||||
t.Errorf("Test %d: expected TTL=%d, got TTL=%d", i, tt.expectedTtl, soaTtl)
|
||||
@@ -631,7 +633,7 @@ func nxDomainBackend(ttl int) plugin.Handler {
|
||||
|
||||
m.Ns = []dns.RR{test.SOA(fmt.Sprintf("example.org. %d IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082540 7200 3600 1209600 3600", ttl))}
|
||||
|
||||
m.MsgHdr.Rcode = dns.RcodeNameError
|
||||
m.Rcode = dns.RcodeNameError
|
||||
w.WriteMsg(m)
|
||||
return dns.RcodeNameError, nil
|
||||
})
|
||||
@@ -657,7 +659,7 @@ func servFailBackend(ttl int) plugin.Handler {
|
||||
|
||||
m.Ns = []dns.RR{test.SOA(fmt.Sprintf("example.org. %d IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082540 7200 3600 1209600 3600", ttl))}
|
||||
|
||||
m.MsgHdr.Rcode = dns.RcodeServerFailure
|
||||
m.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(m)
|
||||
return dns.RcodeServerFailure, nil
|
||||
})
|
||||
|
||||
6
plugin/cache/handler.go
vendored
6
plugin/cache/handler.go
vendored
@@ -100,7 +100,7 @@ func (c *Cache) doPrefetch(ctx context.Context, state request.Request, cw *Respo
|
||||
// that we've gathered sofar. See we copy the frequencies info back
|
||||
// into the new item that was stored in the cache.
|
||||
if i1 := c.exists(state); i1 != nil {
|
||||
i1.Freq.Reset(now, i.Freq.Hits())
|
||||
i1.Reset(now, i.Hits())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +112,9 @@ func (c *Cache) shouldPrefetch(i *item, now time.Time) bool {
|
||||
if c.prefetch <= 0 {
|
||||
return false
|
||||
}
|
||||
i.Freq.Update(c.duration, now)
|
||||
i.Update(c.duration, now)
|
||||
threshold := int(math.Ceil(float64(c.percentage) / 100 * float64(i.origTTL)))
|
||||
return i.Freq.Hits() >= c.prefetch && i.ttl(now) <= threshold
|
||||
return i.Hits() >= c.prefetch && i.ttl(now) <= threshold
|
||||
}
|
||||
|
||||
// Name implements the Handler interface.
|
||||
|
||||
Reference in New Issue
Block a user