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


Golang net.LookupCNAME函数代码示例

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


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

示例1: NewHttpClient

// NewHttpClient is the constructor for the bucket API implementation of HttpClient.
func NewHttpClient(client *http.Client, url string) (*HttpClient, error) {

	// get hostname
	hostname, err := os.Hostname()
	if err != nil {
		return nil, err
	}

	// get canonical hostname
	canonical, err := net.LookupCNAME(hostname)
	if err != nil {
		return nil, err
	}

	// get ipv4
	var ip string
	addrs, err := net.LookupIP(canonical)
	if err != nil {
		return nil, err
	}
	for _, addr := range addrs {
		if ipv4 := addr.To4(); ipv4 != nil {
			ip = ipv4.String()
		}
	}

	// create instance
	return &HttpClient{instance: client, url: url, ipv4: ip, hostname: canonical}, nil

}
开发者ID:navneet-flipkart,项目名称:confd,代码行数:31,代码来源:store.go

示例2: ReturnString

//export ReturnString
func ReturnString(val string) string {
	cname, err := net.LookupCNAME(val)
	if err != nil {
		return "Could not find CNAME"
	}
	return cname
}
开发者ID:ewindfall,项目名称:go-buildmodeshared-howto,代码行数:8,代码来源:dnslib.go

示例3: report

func (me *WorkerDaemon) report(coordinator string, port int) {
	client, err := rpc.DialHTTP("tcp", coordinator)
	if err != nil {
		log.Println("dialing coordinator:", err)
		return
	}

	hostname, err := os.Hostname()
	if err != nil {
		log.Println("hostname", err)
		return
	}

	cname, err := net.LookupCNAME(hostname)
	if err != nil {
		log.Println("cname", err)
		return
	}
	cname = strings.TrimRight(cname, ".")
	req := Registration{
		Address: fmt.Sprintf("%v:%d", cname, port),
		Name:    fmt.Sprintf("%s:%d", hostname, port),
		Version: Version(),
	}

	rep := 0
	err = client.Call("Coordinator.Register", &req, &rep)
	if err != nil {
		log.Println("coordinator rpc error:", err)
	}
}
开发者ID:lht,项目名称:termite,代码行数:31,代码来源:worker.go

示例4: getOurIP

func getOurIP() (ip string, err error) {
	hostname, err := os.Hostname()
	if err != nil {
		return
	}
	return net.LookupCNAME(hostname)
}
开发者ID:Nette22,项目名称:Taipei-Torrent,代码行数:7,代码来源:upnp.go

示例5: Report

func (me *Worker) Report() {
	if me.options.Coordinator == "" {
		return
	}
	client, err := rpc.DialHTTP("tcp", me.options.Coordinator)
	if err != nil {
		log.Println("dialing coordinator:", err)
		return
	}

	cname, err := net.LookupCNAME(Hostname)
	if err != nil {
		log.Println("cname", err)
		return
	}
	cname = strings.TrimRight(cname, ".")
	req := Registration{
		Address: fmt.Sprintf("%v:%d", cname, me.options.Port),
		Name:    fmt.Sprintf("%s:%d", Hostname, me.options.Port),
		Version: Version(),
	}
	rep := 0
	err = client.Call("Coordinator.Register", &req, &rep)
	if err != nil {
		log.Println("coordinator rpc error:", err)
	}
}
开发者ID:janneke,项目名称:termite,代码行数:27,代码来源:worker.go

示例6: ReturnString

//export ReturnString
func ReturnString(val string) *C.char {
	cname, err := net.LookupCNAME(val)
	if err != nil {
		C.CString("Could not find CNAME")
	}
	return C.CString(cname)
}
开发者ID:jbuberel,项目名称:buildmodeshared,代码行数:8,代码来源:dnslib.go

示例7: GetCNAME

// GetCNAME resolves an IP or hostname into a normalized valid CNAME
func GetCNAME(hostname string) (string, error) {
	res, err := net.LookupCNAME(hostname)
	if err != nil {
		return hostname, err
	}
	res = strings.TrimRight(res, ".")
	return res, nil
}
开发者ID:shuhaowu,项目名称:orchestrator,代码行数:9,代码来源:resolve.go

示例8: resourceDnsCnameRecordRead

func resourceDnsCnameRecordRead(d *schema.ResourceData, meta interface{}) error {
	cname, err := net.LookupCNAME(d.Id())
	if err != nil {
		return err
	}

	d.Set("cname", cname)
	return nil
}
开发者ID:Shopify,项目名称:terraform-provider-dns,代码行数:9,代码来源:resource_dns_cname_record.go

示例9: FullyQualifiedHostname

// FullyQualifiedHostname returns the full hostname with domain
func FullyQualifiedHostname() (string, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return "", err
	}

	cname, err := net.LookupCNAME(hostname)
	if err != nil {
		return "", err
	}
	return strings.TrimRight(cname, "."), nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:13,代码来源:netutil.go

示例10: dataSourceDnsCnameRecordRead

func dataSourceDnsCnameRecordRead(d *schema.ResourceData, meta interface{}) error {
	host := d.Get("host").(string)

	cname, err := net.LookupCNAME(host)
	if err != nil {
		return err
	}

	d.Set("cname", cname)
	d.SetId(host)

	return nil
}
开发者ID:steve-jansen,项目名称:terraform-provider-dns,代码行数:13,代码来源:data_dns_cname_record.go

示例11: cname

func cname(host string) (data []byte, err error) {
	cname, err := net.LookupCNAME(host)
	if err != nil {
		err = os.ErrNotExist
		return
	}

	buf := bytes.NewBuffer(make([]byte, 0, len(cname)+1))
	buf.WriteString(cname)
	buf.WriteByte('\n')
	data = buf.Bytes()
	return
}
开发者ID:wwaites,项目名称:nopfs,代码行数:13,代码来源:dns.go

示例12: lcname

func lcname(domain string) {
	cname, err := net.LookupCNAME(domain)

	if err != nil {
		//fmt.Printf("err:%s\n", err)
		return
	}

	fmt.Printf("-------------------\n")
	fmt.Printf(" Information CNAME \n")
	fmt.Printf("-------------------\n")

	fmt.Printf("\t%s\n", cname)
}
开发者ID:41px,项目名称:qdns,代码行数:14,代码来源:qdns.go

示例13: FullHostname

// FullHostname is a best effort attempt to resolve the canonical FQDN of
// the host. On failure it will fall back to a reasonable looking default
// such as 'localhost.' or 'hostname.invalid.'
func FullHostname() string {
	hostname, err := os.Hostname()
	if err != nil || hostname == "localhost" || hostname == "(none)" {
		return "localhost."
	}
	fullname, err := net.LookupCNAME(hostname)
	if err != nil {
		fullname = hostname
		if !strings.Contains(fullname, ".") {
			fullname += ".invalid."
		}
	}
	return fullname
}
开发者ID:carriercomm,项目名称:mantle,代码行数:17,代码来源:hostname.go

示例14: main

func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "Usage:%s hostname\n", os.Args[0])
		os.Exit(1)
	}
	name := os.Args[1]
	cname, err := net.LookupCNAME(name)
	if err != nil {
		fmt.Println("LookupCNAME error:", err.Error())
		os.Exit(1)
	}
	fmt.Println("The host caonical name is:", cname)
	os.Exit(0)
}
开发者ID:jianyongchen,项目名称:GoUnix,代码行数:14,代码来源:5.go

示例15: printInfo

// printInfo prints a brief informative header about the connection
func printInfo(urlTarget string, resp *http.Response) {
	fmt.Println("********* This is gobble version ", version, " ***************")

	urlInfo, err := url.Parse(urlTarget)
	if err != nil {
		return
	}
	cname, _ := net.LookupCNAME(urlInfo.Host)
	ips, _ := net.LookupIP(cname)
	fmt.Println("Connecting to", cname, "  ", ips)
	fmt.Printf("Status %s   Protocol %s  TransferEncoding %v\n", resp.Status,
		resp.Proto, resp.TransferEncoding)
	fmt.Printf("Content Length: %d bytes\n", resp.ContentLength)
	fmt.Println()
}
开发者ID:haskelladdict,项目名称:gobble,代码行数:16,代码来源:gobble.go


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