traefik/vendor/github.com/miekg/dns/reverse.go

44 lines
1 KiB
Go
Raw Normal View History

2017-02-07 21:33:23 +00:00
package dns
// StringToType is the reverse of TypeToString, needed for string parsing.
var StringToType = reverseInt16(TypeToString)
// StringToClass is the reverse of ClassToString, needed for string parsing.
var StringToClass = reverseInt16(ClassToString)
2018-03-02 09:46:04 +00:00
// StringToOpcode is a map of opcodes to strings.
2017-02-07 21:33:23 +00:00
var StringToOpcode = reverseInt(OpcodeToString)
2018-03-02 09:46:04 +00:00
// StringToRcode is a map of rcodes to strings.
2017-02-07 21:33:23 +00:00
var StringToRcode = reverseInt(RcodeToString)
2019-01-07 17:30:06 +00:00
func init() {
// Preserve previous NOTIMP typo, see github.com/miekg/dns/issues/733.
StringToRcode["NOTIMPL"] = RcodeNotImplemented
}
2017-02-07 21:33:23 +00:00
// Reverse a map
func reverseInt8(m map[uint8]string) map[string]uint8 {
n := make(map[string]uint8, len(m))
for u, s := range m {
n[s] = u
}
return n
}
func reverseInt16(m map[uint16]string) map[string]uint16 {
n := make(map[string]uint16, len(m))
for u, s := range m {
n[s] = u
}
return n
}
func reverseInt(m map[int]string) map[string]int {
n := make(map[string]int, len(m))
for u, s := range m {
n[s] = u
}
return n
}