mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-31 16:15:40 +00:00
Resolve (some) linter warnings
This commit is contained in:
@@ -39,7 +39,7 @@ import (
|
||||
|
||||
"github.com/m13253/dns-over-https/doh-client/config"
|
||||
"github.com/m13253/dns-over-https/doh-client/selector"
|
||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
||||
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
"golang.org/x/net/http2"
|
||||
"golang.org/x/net/idna"
|
||||
@@ -305,7 +305,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
||||
|
||||
if len(r.Question) != 1 {
|
||||
log.Println("Number of questions is not 1")
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeFormatError
|
||||
w.WriteMsg(reply)
|
||||
return
|
||||
@@ -356,7 +356,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
||||
return
|
||||
}
|
||||
log.Println(err)
|
||||
reply = jsonDNS.PrepareReply(r)
|
||||
reply = jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return
|
||||
@@ -471,7 +471,7 @@ func (c *Client) findClientIP(w dns.ResponseWriter, r *dns.Msg) (ednsClientAddre
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if ip := remoteAddr.IP; jsonDNS.IsGlobalIP(ip) {
|
||||
if ip := remoteAddr.IP; jsondns.IsGlobalIP(ip) {
|
||||
if ipv4 := ip.To4(); ipv4 != nil {
|
||||
ednsClientAddress = ipv4.Mask(ipv4Mask24)
|
||||
ednsClientNetmask = 24
|
||||
|
||||
@@ -44,7 +44,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
||||
questionName := question.Name
|
||||
questionClass := question.Qclass
|
||||
if questionClass != dns.ClassINET {
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeRefused
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
@@ -80,7 +80,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
||||
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
@@ -111,7 +111,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
@@ -121,7 +121,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
||||
|
||||
return &DNSRequest{
|
||||
response: resp,
|
||||
reply: jsonDNS.PrepareReply(r),
|
||||
reply: jsondns.PrepareReply(r),
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
@@ -148,7 +148,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
||||
return
|
||||
}
|
||||
|
||||
var respJSON jsonDNS.Response
|
||||
var respJSON jsondns.Response
|
||||
err = json.Unmarshal(body, &respJSON)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -162,7 +162,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
||||
}
|
||||
fixEmptyNames(&respJSON)
|
||||
|
||||
fullReply := jsonDNS.Unmarshal(req.reply, &respJSON, req.udpSize, req.ednsClientNetmask)
|
||||
fullReply := jsondns.Unmarshal(req.reply, &respJSON, req.udpSize, req.ednsClientNetmask)
|
||||
buf, err := fullReply.Pack()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -185,7 +185,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
||||
// Fix DNS response empty []RR.Name
|
||||
// Additional section won't be rectified
|
||||
// see: https://stackoverflow.com/questions/52136176/what-is-additional-section-in-dns-and-how-it-works
|
||||
func fixEmptyNames(respJSON *jsonDNS.Response) {
|
||||
func fixEmptyNames(respJSON *jsondns.Response) {
|
||||
for i := range respJSON.Answer {
|
||||
if respJSON.Answer[i].Name == "" {
|
||||
respJSON.Answer[i].Name = "."
|
||||
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/m13253/dns-over-https/doh-client/selector"
|
||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
||||
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -90,7 +90,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
requestBinary, err := r.Pack()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeFormatError
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
@@ -107,7 +107,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
@@ -118,7 +118,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
req, err = http.NewRequest(http.MethodPost, upstream.URL, bytes.NewReader(requestBinary))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
@@ -149,7 +149,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
reply := jsondns.PrepareReply(r)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
@@ -159,7 +159,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
|
||||
return &DNSRequest{
|
||||
response: resp,
|
||||
reply: jsonDNS.PrepareReply(r),
|
||||
reply: jsondns.PrepareReply(r),
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
|
||||
@@ -170,11 +170,11 @@ func (s *Server) parseRequestGoogle(ctx context.Context, w http.ResponseWriter,
|
||||
}
|
||||
|
||||
func (s *Server) generateResponseGoogle(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
||||
respJSON := jsonDNS.Marshal(req.response)
|
||||
respJSON := jsondns.Marshal(req.response)
|
||||
respStr, err := json.Marshal(respJSON)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
|
||||
jsondns.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
||||
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -156,12 +156,12 @@ func (s *Server) parseRequestIETF(ctx context.Context, w http.ResponseWriter, r
|
||||
}
|
||||
|
||||
func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
||||
respJSON := jsonDNS.Marshal(req.response)
|
||||
respJSON := jsondns.Marshal(req.response)
|
||||
req.response.Id = req.transactionID
|
||||
respBytes, err := req.response.Pack()
|
||||
if err != nil {
|
||||
log.Printf("DNS packet construct failure with upstream %s: %v\n", req.currentUpstream, err)
|
||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
|
||||
jsondns.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
||||
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -216,14 +216,14 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||
} else if contentType == "application/dns-udpwireformat" {
|
||||
req = s.parseRequestIETF(ctx, w, r)
|
||||
} else {
|
||||
jsonDNS.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
|
||||
jsondns.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
|
||||
return
|
||||
}
|
||||
if req.errcode == 444 {
|
||||
return
|
||||
}
|
||||
if req.errcode != 0 {
|
||||
jsonDNS.FormatError(w, req.errtext, req.errcode)
|
||||
jsondns.FormatError(w, req.errtext, req.errcode)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
req, err = s.doDNSQuery(ctx, req)
|
||||
if err != nil {
|
||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
||||
jsondns.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
||||
for _, addr := range strings.Split(XForwardedFor, ",") {
|
||||
addr = strings.TrimSpace(addr)
|
||||
ip := net.ParseIP(addr)
|
||||
if jsonDNS.IsGlobalIP(ip) {
|
||||
if jsondns.IsGlobalIP(ip) {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
||||
if XRealIP != "" {
|
||||
addr := strings.TrimSpace(XRealIP)
|
||||
ip := net.ParseIP(addr)
|
||||
if jsonDNS.IsGlobalIP(ip) {
|
||||
if jsondns.IsGlobalIP(ip) {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if ip := remoteAddr.IP; jsonDNS.IsGlobalIP(ip) {
|
||||
if ip := remoteAddr.IP; jsondns.IsGlobalIP(ip) {
|
||||
return ip
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
package jsondns
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -38,11 +38,11 @@ type dnsError struct {
|
||||
|
||||
func FormatError(w http.ResponseWriter, comment string, errcode int) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
errJson := dnsError{
|
||||
errJSON := dnsError{
|
||||
Status: dns.RcodeServerFailure,
|
||||
Comment: comment,
|
||||
}
|
||||
errStr, err := json.Marshal(errJson)
|
||||
errStr, err := json.Marshal(errJSON)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
@@ -21,11 +21,12 @@
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
package jsondns
|
||||
|
||||
import (
|
||||
"github.com/infobloxopen/go-trees/iptree"
|
||||
"net"
|
||||
|
||||
"github.com/infobloxopen/go-trees/iptree"
|
||||
)
|
||||
|
||||
var defaultFilter *iptree.Tree
|
||||
@@ -36,87 +37,87 @@ func init() {
|
||||
// RFC6890
|
||||
// This host on this network
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{0, 0, 0, 0},
|
||||
net.IPMask{255, 0, 0, 0},
|
||||
IP: net.IP{0, 0, 0, 0},
|
||||
Mask: net.IPMask{255, 0, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// Private-Use Networks
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{10, 0, 0, 0},
|
||||
net.IPMask{255, 0, 0, 0},
|
||||
IP: net.IP{10, 0, 0, 0},
|
||||
Mask: net.IPMask{255, 0, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// Shared Address Space
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{100, 64, 0, 0},
|
||||
net.IPMask{255, 192, 0, 0},
|
||||
IP: net.IP{100, 64, 0, 0},
|
||||
Mask: net.IPMask{255, 192, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// Loopback
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{127, 0, 0, 0},
|
||||
net.IPMask{255, 0, 0, 0},
|
||||
IP: net.IP{127, 0, 0, 0},
|
||||
Mask: net.IPMask{255, 0, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// Link Local
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{169, 254, 0, 0},
|
||||
net.IPMask{255, 255, 0, 0},
|
||||
IP: net.IP{169, 254, 0, 0},
|
||||
Mask: net.IPMask{255, 255, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// Private-Use Networks
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{172, 16, 0, 0},
|
||||
net.IPMask{255, 240, 0, 0},
|
||||
IP: net.IP{172, 16, 0, 0},
|
||||
Mask: net.IPMask{255, 240, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// DS-Lite
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{192, 0, 0, 0},
|
||||
net.IPMask{255, 255, 255, 248},
|
||||
IP: net.IP{192, 0, 0, 0},
|
||||
Mask: net.IPMask{255, 255, 255, 248},
|
||||
}, struct{}{})
|
||||
|
||||
// 6to4 Relay Anycast
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{192, 88, 99, 0},
|
||||
net.IPMask{255, 255, 255, 0},
|
||||
IP: net.IP{192, 88, 99, 0},
|
||||
Mask: net.IPMask{255, 255, 255, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// Private-Use Networks
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{192, 168, 0, 0},
|
||||
net.IPMask{255, 255, 0, 0},
|
||||
IP: net.IP{192, 168, 0, 0},
|
||||
Mask: net.IPMask{255, 255, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// Reserved for Future Use & Limited Broadcast
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{240, 0, 0, 0},
|
||||
net.IPMask{240, 0, 0, 0},
|
||||
IP: net.IP{240, 0, 0, 0},
|
||||
Mask: net.IPMask{240, 0, 0, 0},
|
||||
}, struct{}{})
|
||||
|
||||
// RFC6890
|
||||
// Unspecified & Loopback Address
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
|
||||
IP: net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
|
||||
}, struct{}{})
|
||||
|
||||
// Discard-Only Prefix
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
IP: net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
}, struct{}{})
|
||||
|
||||
// Unique-Local
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
IP: net.IP{0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Mask: net.IPMask{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
}, struct{}{})
|
||||
|
||||
// Linked-Scoped Unicast
|
||||
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||
net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
IP: net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Mask: net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
}, struct{}{})
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package jsonDNS
|
||||
package jsondns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
func ExampleFindIP() {
|
||||
func ExampleIsGlobalIP() {
|
||||
fmt.Println(IsGlobalIP(net.ParseIP("127.0.0.1")))
|
||||
fmt.Println(IsGlobalIP(net.IP{192, 168, 1, 1}))
|
||||
fmt.Println(IsGlobalIP(net.ParseIP("8.8.8.8")))
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
package jsondns
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
package jsondns
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -30,12 +30,12 @@ import (
|
||||
|
||||
type QuestionList []Question
|
||||
|
||||
// Fix variant question response in Response.Question
|
||||
//
|
||||
// Solution taken from:
|
||||
// https://engineering.bitnami.com/articles/dealing-with-json-with-non-homogeneous-types-in-go.html
|
||||
// https://archive.is/NU4zR
|
||||
func (ql *QuestionList) UnmarshalJSON(b []byte) error {
|
||||
// Fix variant question response in Response.Question
|
||||
//
|
||||
// Solution taken from:
|
||||
// https://engineering.bitnami.com/articles/dealing-with-json-with-non-homogeneous-types-in-go.html
|
||||
// https://archive.is/NU4zR
|
||||
if len(b) > 0 && b[0] == '[' {
|
||||
return json.Unmarshal(b, (*[]Question)(ql))
|
||||
}
|
||||
@@ -60,13 +60,13 @@ type Response struct {
|
||||
// FIXME: We don't have DNSSEC yet! This bit is not reliable!
|
||||
AD bool `json:"AD"`
|
||||
// Whether the client asked to disable DNSSEC
|
||||
CD bool `json:"CD"`
|
||||
Question QuestionList `json:"Question"`
|
||||
Answer []RR `json:"Answer,omitempty"`
|
||||
Authority []RR `json:"Authority,omitempty"`
|
||||
Additional []RR `json:"Additional,omitempty"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||
CD bool `json:"CD"`
|
||||
Question QuestionList `json:"Question"`
|
||||
Answer []RR `json:"Answer,omitempty"`
|
||||
Authority []RR `json:"Authority,omitempty"`
|
||||
Additional []RR `json:"Additional,omitempty"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||
// Least time-to-live
|
||||
HaveTTL bool `json:"-"`
|
||||
LeastTTL uint32 `json:"-"`
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
package jsondns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
Reference in New Issue
Block a user