Merge pull request #417 from safing/feature/rrcache-json

Add MarshalJSON support to RRCache
This commit is contained in:
Daniel 2021-10-15 16:07:39 +02:00 committed by GitHub
commit 23e8ecafcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package resolver
import (
"context"
"encoding/json"
"fmt"
"net"
"time"
@ -44,6 +45,25 @@ type RRCache struct {
Modified int64
}
func (rrCache *RRCache) MarshalJSON() ([]byte, error) {
var record = struct {
RRCache
Question string
RCode string
Modified time.Time
Expires time.Time
}{
RRCache: *rrCache,
Question: rrCache.Question.String(),
RCode: dns.RcodeToString[rrCache.RCode],
Modified: time.Unix(rrCache.Modified, 0),
Expires: time.Unix(rrCache.Expires, 0),
}
return json.Marshal(record)
}
// ID returns the ID of the RRCache consisting of the domain and question type.
func (rrCache *RRCache) ID() string {
return rrCache.Domain + rrCache.Question.String()