本文整理汇总了Golang中github.com/miekg/dns.RFC3597.ToRFC3597方法的典型用法代码示例。如果您正苦于以下问题:Golang RFC3597.ToRFC3597方法的具体用法?Golang RFC3597.ToRFC3597怎么用?Golang RFC3597.ToRFC3597使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.RFC3597
的用法示例。
在下文中一共展示了RFC3597.ToRFC3597方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dnsResourceRecordToString
// dnsResourceRecordToString converts a RR to a string.
func dnsResourceRecordToString(rr mkdns.RR) string {
rrHeader := rr.Header()
rrType := rrHeader.Rrtype
var data string
switch x := rr.(type) {
default:
// We don't have special handling for this type
logp.Debug("dns", "No special handling for RR type %s", dnsTypeToString(rrType))
unsupportedRR := new(mkdns.RFC3597)
err := unsupportedRR.ToRFC3597(x)
if err == nil {
rData, err := hexStringToString(unsupportedRR.Rdata)
data = rData
if err != nil {
logp.Debug("dns", "%s", err.Error())
}
} else {
logp.Debug("dns", "Rdata for the unhandled RR type %s could not be fetched", dnsTypeToString(rrType))
}
case *mkdns.A:
data = x.A.String()
case *mkdns.AAAA:
data = x.AAAA.String()
case *mkdns.CNAME:
data = x.Target
case *mkdns.MX:
data = fmt.Sprintf("preference %d, %s", x.Preference, x.Mx)
case *mkdns.NS:
data = x.Ns
case *mkdns.PTR:
data = x.Ptr
case *mkdns.RFC3597:
// Miekg/dns lib doesn't handle this type
logp.Debug("dns", "Unknown RR type %s", dnsTypeToString(rrType))
rData, err := hexStringToString(x.Rdata)
data = rData
if err != nil {
logp.Debug("dns", "%s", err.Error())
}
case *mkdns.SOA:
data = fmt.Sprintf("mname %s, rname %s, serial %d, refresh %d, "+
"retry %d, expire %d, minimum %d", x.Ns, x.Mbox,
x.Serial, x.Refresh, x.Retry, x.Expire,
x.Minttl)
case *mkdns.SRV:
data = fmt.Sprintf("priority %d, weight %d, port %d, %s", x.Priority,
x.Weight, x.Port, x.Target)
case *mkdns.TXT:
data = strings.Join(x.Txt, " ")
}
return fmt.Sprintf("%s: ttl %d, class %s, type %s, %s", rrHeader.Name,
int(rrHeader.Ttl), dnsClassToString(rrHeader.Class),
dnsTypeToString(rrType), data)
}
示例2: sectionToResourceRecords
func sectionToResourceRecords(section []dns.RR) []ResourceRecord {
var a []ResourceRecord
for _, r := range section {
x := new(dns.RFC3597)
x.ToRFC3597(r)
a = append(a, ResourceRecord{r.Header().Name,
dns.TypeToString[r.Header().Rrtype],
dns.ClassToString[r.Header().Class],
r.Header().Ttl,
r.Header().Rdlength,
x.Rdata})
}
return a
}
示例3: rrToMapStr
func rrToMapStr(rr mkdns.RR) common.MapStr {
mapStr := common.MapStr{}
rrType := rr.Header().Rrtype
switch x := rr.(type) {
default:
// We don't have special handling for this type
debugf("No special handling for RR type %s", dnsTypeToString(rrType))
unsupportedRR := new(mkdns.RFC3597)
err := unsupportedRR.ToRFC3597(x)
if err == nil {
rData, err := hexStringToString(unsupportedRR.Rdata)
mapStr["data"] = rData
if err != nil {
debugf("%s", err.Error())
}
} else {
debugf("Rdata for the unhandled RR type %s could not be fetched", dnsTypeToString(rrType))
}
case *mkdns.A:
mapStr["data"] = x.A.String()
case *mkdns.AAAA:
mapStr["data"] = x.AAAA.String()
case *mkdns.CNAME:
mapStr["data"] = x.Target
case *mkdns.DNSKEY:
mapStr["flags"] = strconv.Itoa(int(x.Flags))
mapStr["protocol"] = strconv.Itoa(int(x.Protocol))
mapStr["algorithm"] = dnsAlgorithmToString(x.Algorithm)
mapStr["data"] = x.PublicKey
case *mkdns.DS:
mapStr["key_tag"] = strconv.Itoa(int(x.KeyTag))
mapStr["algorithm"] = dnsAlgorithmToString(x.Algorithm)
mapStr["digest_type"] = dnsHashToString(x.DigestType)
mapStr["data"] = strings.ToUpper(x.Digest)
case *mkdns.MX:
mapStr["preference"] = x.Preference
mapStr["data"] = x.Mx
case *mkdns.NS:
mapStr["data"] = x.Ns
case *mkdns.NSEC:
mapStr["type_bits"] = dnsTypeBitsMapToString(x.TypeBitMap)
mapStr["data"] = x.NextDomain
case *mkdns.NSEC3:
mapStr["hash"] = dnsHashToString(x.Hash)
mapStr["flags"] = strconv.Itoa(int(x.Flags))
mapStr["iterations"] = strconv.Itoa(int(x.Iterations))
mapStr["salt"] = dnsSaltToString(x.Salt)
mapStr["type_bits"] = dnsTypeBitsMapToString(x.TypeBitMap)
mapStr["data"] = x.NextDomain
case *mkdns.NSEC3PARAM:
mapStr["hash"] = dnsHashToString(x.Hash)
mapStr["flags"] = strconv.Itoa(int(x.Flags))
mapStr["iterations"] = strconv.Itoa(int(x.Iterations))
mapStr["data"] = dnsSaltToString(x.Salt)
case *mkdns.OPT: // EDNS [RFC6891]
// OPT pseudo-RR is managed in addDnsToMapStr function
return nil
case *mkdns.PTR:
mapStr["data"] = x.Ptr
case *mkdns.RFC3597:
// Miekg/dns lib doesn't handle this type
debugf("Unknown RR type %s", dnsTypeToString(rrType))
rData, err := hexStringToString(x.Rdata)
mapStr["data"] = rData
if err != nil {
debugf("%s", err.Error())
}
case *mkdns.RRSIG:
mapStr["type_covered"] = dnsTypeToString(x.TypeCovered)
mapStr["algorithm"] = dnsAlgorithmToString(x.Algorithm)
mapStr["labels"] = strconv.Itoa(int(x.Labels))
mapStr["original_ttl"] = strconv.FormatInt(int64(x.OrigTtl), 10)
mapStr["expiration"] = mkdns.TimeToString(x.Expiration)
mapStr["inception"] = mkdns.TimeToString(x.Inception)
mapStr["key_tag"] = strconv.Itoa(int(x.KeyTag))
mapStr["signer_name"] = x.SignerName
mapStr["data"] = x.Signature
case *mkdns.SOA:
mapStr["rname"] = x.Mbox
mapStr["serial"] = x.Serial
mapStr["refresh"] = x.Refresh
mapStr["retry"] = x.Retry
mapStr["expire"] = x.Expire
mapStr["minimum"] = x.Minttl
mapStr["data"] = x.Ns
case *mkdns.SRV:
mapStr["priority"] = x.Priority
mapStr["weight"] = x.Weight
mapStr["port"] = x.Port
mapStr["data"] = x.Target
case *mkdns.TXT:
mapStr["data"] = strings.Join(x.Txt, " ")
}
return mapStr
}
示例4: rrToMapStr
// rrToMapStr converts an array of DNSResourceRecord's to an array of MapStr's.
func rrToMapStr(records []mkdns.RR) []common.MapStr {
mapStrArray := make([]common.MapStr, len(records))
for i, rr := range records {
rrHeader := rr.Header()
rrType := rrHeader.Rrtype
mapStr := common.MapStr{
"name": rrHeader.Name,
"type": dnsTypeToString(rrType),
"class": dnsClassToString(rrHeader.Class),
"ttl": strconv.FormatInt(int64(rrHeader.Ttl), 10),
}
mapStrArray[i] = mapStr
switch x := rr.(type) {
default:
// We don't have special handling for this type
logp.Debug("dns", "No special handling for RR type %s", dnsTypeToString(rrType))
unsupportedRR := new(mkdns.RFC3597)
err := unsupportedRR.ToRFC3597(x)
if err == nil {
rData, err := hexStringToString(unsupportedRR.Rdata)
mapStr["data"] = rData
if err != nil {
logp.Debug("dns", "%s", err.Error())
}
} else {
logp.Debug("dns", "Rdata for the unhandled RR type %s could not be fetched", dnsTypeToString(rrType))
}
case *mkdns.A:
mapStr["data"] = x.A.String()
case *mkdns.AAAA:
mapStr["data"] = x.AAAA.String()
case *mkdns.CNAME:
mapStr["data"] = x.Target
case *mkdns.MX:
mapStr["preference"] = x.Preference
mapStr["data"] = x.Mx
case *mkdns.NS:
mapStr["data"] = x.Ns
case *mkdns.PTR:
mapStr["data"] = x.Ptr
case *mkdns.RFC3597:
// Miekg/dns lib doesn't handle this type
//TODO: write a test for this.
logp.Debug("dns", "Unknown RR type %s", dnsTypeToString(rrType))
rData, err := hexStringToString(x.Rdata)
mapStr["data"] = rData
if err != nil {
logp.Debug("dns", "%s", err.Error())
}
case *mkdns.SOA:
mapStr["rname"] = x.Mbox
mapStr["serial"] = x.Serial
mapStr["refresh"] = x.Refresh
mapStr["retry"] = x.Retry
mapStr["expire"] = x.Expire
mapStr["minimum"] = x.Minttl
mapStr["data"] = x.Ns
case *mkdns.SRV:
mapStr["priority"] = x.Priority
mapStr["weight"] = x.Weight
mapStr["port"] = x.Port
mapStr["data"] = x.Target
case *mkdns.TXT:
mapStr["data"] = strings.Join(x.Txt, " ")
}
}
return mapStrArray
}