Skip to content

Commit

Permalink
Fix ExamplePrivateHandle (miekg#1354)
Browse files Browse the repository at this point in the history
Signed-off-by: Miek Gieben <miek@miek.nl>
  • Loading branch information
miekg authored and aanm committed Jul 29, 2022
1 parent 97e71e6 commit 0ce87f8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions example_test.go
Expand Up @@ -121,21 +121,23 @@ func (rd *APAIR) Len() int {
func ExamplePrivateHandle() {
dns.PrivateHandle("APAIR", TypeAPAIR, NewAPAIR)
defer dns.PrivateHandleRemove(TypeAPAIR)
var oldId = dns.Id
dns.Id = func() uint16 { return 3 }
defer func() { dns.Id = oldId }()

rr, err := dns.NewRR("miek.nl. APAIR (1.2.3.4 1.2.3.5)")
if err != nil {
log.Fatal("could not parse APAIR record: ", err)
}
fmt.Println(rr)
// Output: miek.nl. 3600 IN APAIR 1.2.3.4 1.2.3.5
fmt.Println(rr) // see first line of Output below

m := new(dns.Msg)
m.Id = 12345
m.SetQuestion("miek.nl.", TypeAPAIR)
m.Answer = append(m.Answer, rr)

fmt.Println(m)
// ;; opcode: QUERY, status: NOERROR, id: 12345
// Output: miek.nl. 3600 IN APAIR 1.2.3.4 1.2.3.5
// ;; opcode: QUERY, status: NOERROR, id: 3
// ;; flags: rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
//
// ;; QUESTION SECTION:
Expand Down

0 comments on commit 0ce87f8

Please sign in to comment.