当前位置: 首页>>代码示例>>Golang>>正文


Golang zkns.ReadAddrs函数代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/zk/zkns.ReadAddrs函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadAddrs函数的具体用法?Golang ReadAddrs怎么用?Golang ReadAddrs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ReadAddrs函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getA

// An A record is generated when there is only one ZknsAddr, it
// has no port component and provides an IPv4 address.
func (rz *zknsResolver) getA(qname string) ([]*pdnsReply, error) {
	if !strings.HasSuffix(qname, rz.zknsDomain) {
		return nil, fmt.Errorf("invalid domain for query: %v", qname)
	}
	if qname[0] == '_' {
		// Since PDNS probes for all types, use some heuristics to limit error noise.
		relog.Debug("skipping A query: %v", qname)
		return nil, nil
	}
	zkname := qname[:len(qname)-len(rz.zknsDomain)]
	nameParts := reverse(strings.Split(zkname, "."))
	zkPath := path.Join(rz.zkRoot, path.Join(nameParts...))
	addrs, err := zkns.ReadAddrs(rz.zconn, zkPath)
	if err != nil {
		return nil, err
	}

	if len(addrs.Entries) != 1 || addrs.Entries[0].IPv4 == "" {
		// Since PDNS probes for all types, this isn't really an error worth mentioning.
		// return nil, fmt.Errorf("invalid response for CNAME query: %v", qname)
		return nil, nil
	}

	return []*pdnsReply{&pdnsReply{qname, "IN", "A", defaultTTL, defaultId, addrs.Entries[0].IPv4}}, nil
}
开发者ID:Eric-Chen,项目名称:vitess,代码行数:27,代码来源:pdns.go

示例2: getSRV

func (rz *zknsResolver) getSRV(qname string) ([]*pdnsReply, error) {
	if !strings.HasSuffix(qname, rz.zknsDomain) {
		return nil, fmt.Errorf("invalid domain for query: %v", qname)
	}
	zkname := qname[:len(qname)-len(rz.zknsDomain)]
	nameParts := strings.Split(zkname, ".")
	portName := nameParts[0]
	if portName[0] != '_' {
		// Since PDNS probes for all types, this isn't really an error worth mentioning.
		// fmt.Errorf("invalid port name for query: %v", portName)
		relog.Debug("skipping SRV query: %v", qname)
		return nil, nil
	}
	nameParts = reverse(nameParts[1:])

	zkPath := path.Join(rz.zkRoot, path.Join(nameParts...))
	addrs, err := zkns.ReadAddrs(rz.zconn, zkPath)
	if err != nil {
		return nil, err
	}

	replies := make([]*pdnsReply, 0, 16)
	for _, addr := range addrs.Entries {
		content := fmt.Sprintf("%v\t%v %v %v", defaultPriority, defaultWeight, addr.NamedPortMap[portName], addr.Host)
		replies = append(replies, &pdnsReply{qname, "IN", "SRV", defaultTTL, defaultId, content})
	}
	return replies, nil
}
开发者ID:Eric-Chen,项目名称:vitess,代码行数:28,代码来源:pdns.go

示例3: getCNAME

// An CNAME record is generated when there is only one ZknsAddr, it
// has no port component. Multiple CNAMEs violate DNS protocols despite
// support in some versions of BIND.
func (rz *zknsResolver) getCNAME(qname string) ([]*pdnsReply, error) {
	if !strings.HasSuffix(qname, rz.zknsDomain) {
		return nil, fmt.Errorf("invalid domain for query: %v", qname)
	}
	if qname[0] == '_' {
		// Since PDNS probes for all types, use some heuristics to limit error noise.
		log.Infof("skipping CNAME query: %v", qname)
		return nil, nil
	}
	zkname := qname[:len(qname)-len(rz.zknsDomain)]
	nameParts := reverse(strings.Split(zkname, "."))
	zkPath := path.Join(rz.zkRoot, path.Join(nameParts...))
	addrs, err := zkns.ReadAddrs(rz.zconn, zkPath)
	if err != nil {
		return nil, err
	}

	if !addrs.IsValidCNAME() {
		log.Warningf("invalid CNAME record addrs at path %v", zkPath)
		// Since PDNS probes for all types, this isn't really an error worth propagating.
		// return nil, fmt.Errorf("invalid response for CNAME query: %v", qname)
		return nil, nil
	}

	return []*pdnsReply{&pdnsReply{qname, "IN", "CNAME", defaultTTL, defaultId, addrs.Entries[0].Host}}, nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:29,代码来源:pdns.go

示例4: getA

// An A record is generated when there is only one ZknsAddr, it
// has no port component and provides an IPv4 address.
// FIXME(msolo) Multiple IP addresses could be handed out.
func (rz *zknsResolver) getA(qname string) ([]*pdnsReply, error) {
	if !strings.HasSuffix(qname, rz.zknsDomain) {
		return nil, fmt.Errorf("invalid domain for query: %v", qname)
	}
	if qname[0] == '_' {
		// Since PDNS probes for all types, use some heuristics to limit error noise.
		log.Infof("skipping A query, looks like SRV name: %v", qname)
		return nil, nil
	}
	zkname := qname[:len(qname)-len(rz.zknsDomain)]
	nameParts := reverse(strings.Split(zkname, "."))
	zkPath := path.Join(rz.zkRoot, path.Join(nameParts...))
	addrs, err := zkns.ReadAddrs(rz.zconn, zkPath)
	if err != nil {
		return nil, err
	}

	if !addrs.IsValidA() {
		log.Warningf("invalid A record addrs at path %v", zkPath)
		// Since PDNS probes for all types, this isn't really an error worth propagating.
		// return nil, fmt.Errorf("invalid response for A query: %v", qname)
		return nil, nil
	}

	replies := make([]*pdnsReply, len(addrs.Entries))
	for i, entry := range addrs.Entries {
		replies[i] = &pdnsReply{qname, "IN", "A", defaultTTL, defaultId, entry.IPv4}
	}
	// Shuffle replies since that seems like the only reasonable strategy in a
	// stateless distributed environment.
	for i := range replies {
		j := rand.Intn(i + 1)
		replies[i], replies[j] = replies[j], replies[i]
	}
	return replies, nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:39,代码来源:pdns.go


注:本文中的github.com/youtube/vitess/go/zk/zkns.ReadAddrs函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。