From 023972bb19acba71e5a6a94d0fcf1d502d020e44 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Fri, 16 Oct 2015 17:01:49 +0100 Subject: [PATCH] Expose TypeToRR --- dns_test.go | 4 ++-- msg.go | 2 +- privaterr.go | 8 ++++---- types_generate.go | 14 +++++++------- ztypes.go | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/dns_test.go b/dns_test.go index 7cf810ea..58fab4ca 100644 --- a/dns_test.go +++ b/dns_test.go @@ -428,7 +428,7 @@ func TestToRFC3597(t *testing.T) { func TestNoRdataPack(t *testing.T) { data := make([]byte, 1024) - for typ, fn := range typeToRR { + for typ, fn := range TypeToRR { r := fn() *r.Header() = RR_Header{Name: "miek.nl.", Rrtype: typ, Class: ClassINET, Ttl: 3600} _, err := PackRR(r, data, 0, nil, false) @@ -441,7 +441,7 @@ func TestNoRdataPack(t *testing.T) { // TODO(miek): fix dns buffer too small errors this throws func TestNoRdataUnpack(t *testing.T) { data := make([]byte, 1024) - for typ, fn := range typeToRR { + for typ, fn := range TypeToRR { if typ == TypeSOA || typ == TypeTSIG || typ == TypeWKS { // SOA, TSIG will not be seen (like this) in dyn. updates? // WKS is an bug, but...deprecated record. diff --git a/msg.go b/msg.go index 96d69a24..6f0d69c6 100644 --- a/msg.go +++ b/msg.go @@ -1383,7 +1383,7 @@ func UnpackRR(msg []byte, off int) (rr RR, off1 int, err error) { } end := off + int(h.Rdlength) // make an rr of that type and re-unpack. - mk, known := typeToRR[h.Rrtype] + mk, known := TypeToRR[h.Rrtype] if !known { rr = new(RFC3597) } else { diff --git a/privaterr.go b/privaterr.go index 7290791b..c78f8859 100644 --- a/privaterr.go +++ b/privaterr.go @@ -33,7 +33,7 @@ type PrivateRR struct { func mkPrivateRR(rrtype uint16) *PrivateRR { // Panics if RR is not an instance of PrivateRR. - rrfunc, ok := typeToRR[rrtype] + rrfunc, ok := TypeToRR[rrtype] if !ok { panic(fmt.Sprintf("dns: invalid operation with Private RR type %d", rrtype)) } @@ -43,7 +43,7 @@ func mkPrivateRR(rrtype uint16) *PrivateRR { case *PrivateRR: return rr } - panic(fmt.Sprintf("dns: RR is not a PrivateRR, typeToRR[%d] generator returned %T", rrtype, anyrr)) + panic(fmt.Sprintf("dns: RR is not a PrivateRR, TypeToRR[%d] generator returned %T", rrtype, anyrr)) } // Header return the RR header of r. @@ -71,7 +71,7 @@ func (r *PrivateRR) copy() RR { func PrivateHandle(rtypestr string, rtype uint16, generator func() PrivateRdata) { rtypestr = strings.ToUpper(rtypestr) - typeToRR[rtype] = func() RR { return &PrivateRR{RR_Header{}, generator()} } + TypeToRR[rtype] = func() RR { return &PrivateRR{RR_Header{}, generator()} } TypeToString[rtype] = rtypestr StringToType[rtypestr] = rtype @@ -108,7 +108,7 @@ func PrivateHandle(rtypestr string, rtype uint16, generator func() PrivateRdata) func PrivateHandleRemove(rtype uint16) { rtypestr, ok := TypeToString[rtype] if ok { - delete(typeToRR, rtype) + delete(TypeToRR, rtype) delete(TypeToString, rtype) delete(typeToparserFunc, rtype) delete(StringToType, rtypestr) diff --git a/types_generate.go b/types_generate.go index 63b4d31d..53690141 100644 --- a/types_generate.go +++ b/types_generate.go @@ -2,7 +2,7 @@ // types_generate.go is meant to run with go generate. It will use // go/{importer,types} to track down all the RR struct types. Then for each type -// it will generate conversion tables (typeToRR and TypeToString) and banal +// it will generate conversion tables (TypeToRR and TypeToString) and banal // methods (len, Header, copy) based on the struct tags. The generated source is // written to ztypes.go, and is meant to be checked into git. package main @@ -40,16 +40,16 @@ import ( ` -var typeToRR = template.Must(template.New("typeToRR").Parse(` -// Map of constructors for each RR type. -var typeToRR = map[uint16]func() RR{ +var TypeToRR = template.Must(template.New("TypeToRR").Parse(` +// TypeToRR is a map of constructors for each RR type. +var TypeToRR = map[uint16]func() RR{ {{range .}}{{if ne . "RFC3597"}} Type{{.}}: func() RR { return new({{.}}) }, {{end}}{{end}} } `)) var typeToString = template.Must(template.New("typeToString").Parse(` -// TypeToString is a map of strings for each RR wire type. +// TypeToString is a map of strings for each RR type. var TypeToString = map[uint16]string{ {{range .}}{{if ne . "NSAPPTR"}} Type{{.}}: "{{.}}", {{end}}{{end}} TypeNSAPPTR: "NSAP-PTR", @@ -136,8 +136,8 @@ func main() { b := &bytes.Buffer{} b.WriteString(packageHdr) - // Generate typeToRR - fatalIfErr(typeToRR.Execute(b, namedTypes)) + // Generate TypeToRR + fatalIfErr(TypeToRR.Execute(b, namedTypes)) // Generate typeToString fatalIfErr(typeToString.Execute(b, numberedTypes)) diff --git a/ztypes.go b/ztypes.go index 6c9cb447..3d0f9aef 100644 --- a/ztypes.go +++ b/ztypes.go @@ -8,8 +8,8 @@ import ( "net" ) -// Map of constructors for each RR type. -var typeToRR = map[uint16]func() RR{ +// TypeToRR is a map of constructors for each RR type. +var TypeToRR = map[uint16]func() RR{ TypeA: func() RR { return new(A) }, TypeAAAA: func() RR { return new(AAAA) }, TypeAFSDB: func() RR { return new(AFSDB) }, @@ -80,7 +80,7 @@ var typeToRR = map[uint16]func() RR{ TypeX25: func() RR { return new(X25) }, } -// TypeToString is a map of strings for each RR wire type. +// TypeToString is a map of strings for each RR type. var TypeToString = map[uint16]string{ TypeA: "A", TypeAAAA: "AAAA",