Documentation
¶
Overview ¶
Example ¶
package main
import (
"encoding/json"
"fmt"
"github.com/linkdata/dnsjson"
"github.com/miekg/dns"
)
func main() {
msg := new(dns.Msg)
msg.SetQuestion("example.com.", dns.TypeA)
msg.Id = 1234
jbytes, err := json.MarshalIndent((*dnsjson.Msg)(msg), "", " ")
if err == nil {
fmt.Println(string(jbytes))
var msg2 dnsjson.Msg
if err = json.Unmarshal(jbytes, &msg2); err == nil {
fmt.Println(dns.Msg(msg2).Question[0].Name)
}
}
if err != nil {
fmt.Println(err)
}
}
Output: { "id": 1234, "msgHdr": { "opcode": "QUERY", "rd": true, "rcode": "NOERROR" }, "question": [ { "name": "example.com.", "qtype": "A", "qclass": "IN" } ] } example.com.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmptyInput = errors.New("empty input") ErrInvalidJSON = errors.New("invalid JSON") ErrInvalidMessage = errors.New("invalid message") ErrQuestionQType = errors.New("question qtype") ErrQuestionQClass = errors.New("question qclass") ErrAnswerSection = errors.New("answer") ErrNsSection = errors.New("ns") ErrExtraSection = errors.New("extra") ErrUnknownType = errors.New("unknown type") ErrUnknownClass = errors.New("unknown class") ErrInvalidStringSlice = errors.New("invalid string slice") ErrEDNSOptionEntry = errors.New("edns option entry type") ErrEDNSOption = errors.New("edns option") ErrEDNSOptionsNotArray = errors.New("opt options must be array") ErrEDNSOptionNoCode = errors.New("opt option missing code") ErrUint8SliceType = errors.New("uint8 slice type") ErrUint8SliceElement = errors.New("uint8 slice element") ErrUint8SliceRange = errors.New("uint8 slice range") ErrNegativeValue = errors.New("negative value") ErrInvalidNumber = errors.New("invalid number") ErrInvalidNumberType = errors.New("invalid number type") )
Functions ¶
This section is empty.
Types ¶
type MessageJSON ¶
type MessageJSON struct {
ID uint16 `json:"id"`
MsgHdr MsgHdrJSON `json:"msgHdr"`
Question []QuestionJSON `json:"question"`
Answer []RRJSON `json:"answer,omitempty"`
Ns []RRJSON `json:"ns,omitempty"`
Extra []RRJSON `json:"extra,omitempty"`
}
MessageJSON is the top-level JSON shape for dns.Msg.
type MsgHdrJSON ¶ added in v1.0.0
type MsgHdrJSON struct {
QR bool `json:"qr,omitempty"`
Opcode string `json:"opcode"`
AA bool `json:"aa,omitempty"`
TC bool `json:"tc,omitempty"`
RD bool `json:"rd,omitempty"`
RA bool `json:"ra,omitempty"`
Z bool `json:"z,omitempty"`
AD bool `json:"ad,omitempty"`
CD bool `json:"cd,omitempty"`
Rcode string `json:"rcode"`
}
type QuestionJSON ¶ added in v1.0.0
Click to show internal directories.
Click to hide internal directories.