From 80e97d6439ee70c100a1b899f674b3c4a7771dff Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 13 Mar 2011 17:54:12 +0100 Subject: [PATCH] Add generic New() function --- Makefile | 1 + _examples/q/q.go | 9 +++------ new.go | 9 +++------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index d33899c3..ffb875f9 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ GOFILES=\ config.go\ server.go \ nsec3.go \ + new.go \ # y.go\ include $(GOROOT)/src/Make.pkg diff --git a/_examples/q/q.go b/_examples/q/q.go index 5918e8b5..3f22be7a 100644 --- a/_examples/q/q.go +++ b/_examples/q/q.go @@ -89,13 +89,10 @@ Flags: m.MsgHdr.RecursionDesired = *rd m.Question = make([]dns.Question, 1) if *dnssec || *nsid { - opt := new(dns.RR_OPT) - opt.Hdr = dns.RR_Header{Name: "", Rrtype: dns.TypeOPT} - opt.SetVersion(0) - opt.SetDo() - opt.SetUDPSize(dns.DefaultMsgSize) + opt := dns.New(dns.TypeOPT) + opt.(*dns.RR_OPT).SetDo() if *nsid { - opt.SetNsid("") + opt.(*dns.RR_OPT).SetNsid("") } m.Extra = make([]dns.RR, 1) m.Extra[0] = opt diff --git a/new.go b/new.go index 8c785997..d7e44b60 100644 --- a/new.go +++ b/new.go @@ -9,9 +9,10 @@ func New(i int) RR { rr = mk() } + rr.Header().Ttl = DefaultTtl + rr.Header().Class = ClassINET + rr.Header().Rrtype = uint16(i) switch t := rr.(type) { - case *RR_RFC3597: - t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)} case *RR_TSIG: t.Hdr = RR_Header{Ttl: 0, Class: ClassANY, Rrtype: uint16(i)} t.Fudge = 300 @@ -19,10 +20,6 @@ func New(i int) RR { t.Hdr = RR_Header{Name: "", Ttl: 0, Class: 0, Rrtype: uint16(i)} t.SetVersion(0) t.SetUDPSize(DefaultMsgSize) - case *RR_A: - t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)} - case *RR_AAAA: - t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)} } return rr }