Add TypeToTypeString and ClassToClassString
After some discussion with Robert Edmonds, these helper functions seems in order. It is not what he requested (that was an RRType and RRClass as new types), but is does make sense to add some convience functions to save some typing. The dns package itself also used these function (4 times). So clearly there is a need. I'm not completely sold about the names.
This commit is contained in:
parent
eaa57c3335
commit
c72535f2d6
20
defaults.go
20
defaults.go
|
@ -281,3 +281,23 @@ func ReverseAddr(addr string) (arpa string, err error) {
|
|||
buf = append(buf, "ip6.arpa."...)
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
// TypeToTypeString converts a uint16 RR type to its string equivalent.
|
||||
// If the type isn't found the string 'TYPE<number>' is returned.
|
||||
func TypeToTypeString(t uint16) string {
|
||||
if t1, ok := TypeToString[t]; ok {
|
||||
return t1
|
||||
} else {
|
||||
return "TYPE" + strconv.Itoa(int(t))
|
||||
}
|
||||
}
|
||||
|
||||
// ClassToClassString converts a uint16 RR class to its string equivalent.
|
||||
// If the class isn't found the string 'CLASS<number>' is returned.
|
||||
func ClassToClassString(c uint16) string {
|
||||
if c1, ok := ClassToString[c]; ok {
|
||||
return c1
|
||||
} else {
|
||||
return "CLASS" + strconv.Itoa(int(c))
|
||||
}
|
||||
}
|
||||
|
|
31
types.go
31
types.go
|
@ -167,17 +167,8 @@ func (q *Question) String() (s string) {
|
|||
} else {
|
||||
s = ";" + q.Name + "\t"
|
||||
}
|
||||
if _, ok := ClassToString[q.Qclass]; ok {
|
||||
s += ClassToString[q.Qclass] + "\t"
|
||||
} else {
|
||||
s += "CLASS" + strconv.Itoa(int(q.Qtype))
|
||||
}
|
||||
|
||||
if _, ok := TypeToString[q.Qtype]; ok {
|
||||
s += " " + TypeToString[q.Qtype]
|
||||
} else {
|
||||
s += " " + "TYPE" + strconv.Itoa(int(q.Qtype))
|
||||
}
|
||||
s += ClassToClassString(q.Qclass) + "\t"
|
||||
s += " " + TypeToTypeString(q.Qtype)
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -727,8 +718,9 @@ func (rr *RRSIG) copy() RR {
|
|||
}
|
||||
|
||||
func (rr *RRSIG) String() string {
|
||||
return rr.Hdr.String() + TypeToString[rr.TypeCovered] +
|
||||
" " + strconv.Itoa(int(rr.Algorithm)) +
|
||||
s := rr.Hdr.String()
|
||||
s += TypeToTypeString(rr.TypeCovered)
|
||||
s += " " + strconv.Itoa(int(rr.Algorithm)) +
|
||||
" " + strconv.Itoa(int(rr.Labels)) +
|
||||
" " + strconv.FormatInt(int64(rr.OrigTtl), 10) +
|
||||
" " + TimeToString(rr.Expiration) +
|
||||
|
@ -736,6 +728,7 @@ func (rr *RRSIG) String() string {
|
|||
" " + strconv.Itoa(int(rr.KeyTag)) +
|
||||
" " + rr.SignerName +
|
||||
" " + rr.Signature
|
||||
return s
|
||||
}
|
||||
|
||||
func (rr *RRSIG) len() int {
|
||||
|
@ -755,11 +748,7 @@ func (rr *NSEC) copy() RR { return &NSEC{*rr.Hdr.copyHeader(), rr.Next
|
|||
func (rr *NSEC) String() string {
|
||||
s := rr.Hdr.String() + rr.NextDomain
|
||||
for i := 0; i < len(rr.TypeBitMap); i++ {
|
||||
if _, ok := TypeToString[rr.TypeBitMap[i]]; ok {
|
||||
s += " " + TypeToString[rr.TypeBitMap[i]]
|
||||
} else {
|
||||
s += " " + "TYPE" + strconv.Itoa(int(rr.TypeBitMap[i]))
|
||||
}
|
||||
s += " " + TypeToTypeString(rr.TypeBitMap[i])
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -1026,11 +1015,7 @@ func (rr *NSEC3) String() string {
|
|||
" " + saltToString(rr.Salt) +
|
||||
" " + rr.NextDomain
|
||||
for i := 0; i < len(rr.TypeBitMap); i++ {
|
||||
if _, ok := TypeToString[rr.TypeBitMap[i]]; ok {
|
||||
s += " " + TypeToString[rr.TypeBitMap[i]]
|
||||
} else {
|
||||
s += " " + "TYPE" + strconv.Itoa(int(rr.TypeBitMap[i]))
|
||||
}
|
||||
s += " " + TypeToTypeString(rr.TypeBitMap[i])
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue