本文整理汇总了Golang中github.com/skynetservices/skydns/msg.Service.NewCNAME方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.NewCNAME方法的具体用法?Golang Service.NewCNAME怎么用?Golang Service.NewCNAME使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skynetservices/skydns/msg.Service
的用法示例。
在下文中一共展示了Service.NewCNAME方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CNAMERecords
func (s *server) CNAMERecords(q dns.Question, name string) (records []dns.RR, err error) {
path, _ := msg.PathWithWildcard(name) // no wildcards here
r, err := get(s.client, path, true)
if err != nil {
return nil, err
}
if !r.Node.Dir {
serv := new(msg.Service)
if err := json.Unmarshal([]byte(r.Node.Value), serv); err != nil {
s.config.log.Infof("failed to parse json: %s", err.Error())
return nil, err
}
ip := net.ParseIP(serv.Host)
ttl := s.calculateTtl(r.Node, serv)
serv.Key = r.Node.Key
serv.Ttl = ttl
if ip == nil {
records = append(records, serv.NewCNAME(q.Name, dns.Fqdn(serv.Host)))
}
}
return records, nil
}
示例2: AddressRecords
func (s *server) AddressRecords(q dns.Question, name string, previousRecords []dns.RR) (records []dns.RR, err error) {
path, star := msg.PathWithWildcard(name)
r, err := get(s.client, path, true)
if err != nil {
return nil, err
}
if !r.Node.Dir { // single element
serv := new(msg.Service)
if err := json.Unmarshal([]byte(r.Node.Value), serv); err != nil {
s.config.log.Infof("failed to parse json: %s", err.Error())
return nil, err
}
ip := net.ParseIP(serv.Host)
ttl := s.calculateTtl(r.Node, serv)
serv.Ttl = ttl
serv.Key = r.Node.Key
switch {
case ip == nil:
// Try to resolve as CNAME if it's not an IP.
newRecord := serv.NewCNAME(q.Name, dns.Fqdn(serv.Host))
if len(previousRecords) > 7 {
s.config.log.Errorf("CNAME lookup limit of 8 exceeded for %s", newRecord)
return nil, fmt.Errorf("exceeded CNAME lookup limit")
}
if s.isDuplicateCNAME(newRecord, previousRecords) {
s.config.log.Errorf("CNAME loop detected for record %s", newRecord)
return nil, fmt.Errorf("detected CNAME loop")
}
records = append(records, newRecord)
nextRecords, err := s.AddressRecords(dns.Question{Name: dns.Fqdn(serv.Host), Qtype: q.Qtype, Qclass: q.Qclass}, strings.ToLower(dns.Fqdn(serv.Host)), append(previousRecords, newRecord))
if err != nil {
// This means we can not complete the CNAME, this is OK, but
// if we return an error this will trigger an NXDOMAIN.
// We also don't want to return the CNAME, because of the
// no other data rule. So return nothing and let NODATA
// kick in (via a hack).
return records, fmt.Errorf("incomplete CNAME chain")
}
records = append(records, nextRecords...)
case ip.To4() != nil && q.Qtype == dns.TypeA:
records = append(records, serv.NewA(q.Name, ip.To4()))
case ip.To4() == nil && q.Qtype == dns.TypeAAAA:
records = append(records, serv.NewAAAA(q.Name, ip.To16()))
}
return records, nil
}
nodes, err := s.loopNodes(&r.Node.Nodes, strings.Split(msg.Path(name), "/"), star, nil)
if err != nil {
s.config.log.Infof("failed to parse json: %s", err.Error())
return nil, err
}
for _, serv := range nodes {
ip := net.ParseIP(serv.Host)
switch {
case ip == nil:
// TODO: deduplicate with above code
// Try to resolve as CNAME if it's not an IP.
newRecord := serv.NewCNAME(q.Name, dns.Fqdn(serv.Host))
if len(previousRecords) > 7 {
s.config.log.Errorf("CNAME lookup limit of 8 exceeded for %s", newRecord)
return nil, fmt.Errorf("exceeded CNAME lookup limit")
}
if s.isDuplicateCNAME(newRecord, previousRecords) {
s.config.log.Errorf("CNAME loop detected for record %s", newRecord)
return nil, fmt.Errorf("detected CNAME loop")
}
records = append(records, newRecord)
nextRecords, err := s.AddressRecords(dns.Question{Name: dns.Fqdn(serv.Host), Qtype: q.Qtype, Qclass: q.Qclass}, strings.ToLower(dns.Fqdn(serv.Host)), append(previousRecords, newRecord))
if err != nil {
// This means we can not complete the CNAME, this is OK, but
// if we return an error this will trigger an NXDOMAIN.
// We also don't want to return the CNAME, because of the
// no other data rule. So return nothing and let NODATA
// kick in (via a hack).
return records, fmt.Errorf("incomplete CNAME chain")
}
records = append(records, nextRecords...)
case ip.To4() != nil && q.Qtype == dns.TypeA:
records = append(records, serv.NewA(q.Name, ip.To4()))
case ip.To4() == nil && q.Qtype == dns.TypeAAAA:
records = append(records, serv.NewAAAA(q.Name, ip.To16()))
}
}
if s.config.RoundRobin {
switch l := len(records); l {
case 2:
if dns.Id()%2 == 0 {
records[0], records[1] = records[1], records[0]
}
default:
// Do a minimum of l swap, maximum of 4l swaps
for j := 0; j < l*(int(dns.Id())%4+1); j++ {
q := int(dns.Id()) % l
p := int(dns.Id()) % l
if q == p {
p = (p + 1) % l
}
records[q], records[p] = records[p], records[q]
//.........这里部分代码省略.........