Skip to content

Commit

Permalink
Detect empty expiry with IsZero()
Browse files Browse the repository at this point in the history
  • Loading branch information
bookmoons committed Jun 28, 2019
1 parent 0a68116 commit 5dd4216
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *cache) get(qname string) RRs {
rrs := make(RRs, len(e))
now := time.Now()
for rr, _ := range e {
if rr.Expiry != emptyTime && now.After(rr.Expiry) {
if !rr.Expiry.IsZero() && now.After(rr.Expiry) {
delete(e, rr)
} else {
rrs[i] = rr
Expand Down
2 changes: 1 addition & 1 deletion resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestTTL(t *testing.T) {
st.Expect(t, err, nil)
st.Expect(t, len(rrs) >= 4, true)
rr := rrs[0]
st.Expect(t, rr.Expiry != emptyTime, true)
st.Expect(t, !rr.Expiry.IsZero(), true)
}

var testResolver *Resolver
Expand Down
5 changes: 1 addition & 4 deletions rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ type RRs []RR
// It is used to save allocations at runtime.
var emptyRRs = RRs{}

// emptyTime is used to detect an empty expiry time.
var emptyTime = time.Time{}

// ICANN specifies that DNS servers should return the special value 127.0.53.53
// for A record queries of TLDs that have recently entered the root zone,
// that have a high likelyhood of colliding with private DNS names.
Expand All @@ -37,7 +34,7 @@ const NameCollision = "127.0.53.53"

// String returns a string representation of an RR in zone-file format.
func (rr *RR) String() string {
if rr.Expiry == emptyTime {
if rr.Expiry.IsZero() {
return rr.Name + "\t 3600\tIN\t" + rr.Type + "\t" + rr.Value
} else {
ttl := ttlString(rr.TTL)
Expand Down

0 comments on commit 5dd4216

Please sign in to comment.