mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Merge pull request #417 from safing/feature/rrcache-json
Add MarshalJSON support to RRCache
This commit is contained in:
commit
23e8ecafcf
1 changed files with 20 additions and 0 deletions
|
@ -2,6 +2,7 @@ package resolver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -44,6 +45,25 @@ type RRCache struct {
|
||||||
Modified int64
|
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.
|
// ID returns the ID of the RRCache consisting of the domain and question type.
|
||||||
func (rrCache *RRCache) ID() string {
|
func (rrCache *RRCache) ID() string {
|
||||||
return rrCache.Domain + rrCache.Question.String()
|
return rrCache.Domain + rrCache.Question.String()
|
||||||
|
|
Loading…
Add table
Reference in a new issue