本文整理汇总了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
}
示例2: ReturnString
//export ReturnString
func ReturnString(val string) string {
cname, err := net.LookupCNAME(val)
if err != nil {
return "Could not find CNAME"
}
return cname
}
示例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)
}
}
示例4: getOurIP
func getOurIP() (ip string, err error) {
hostname, err := os.Hostname()
if err != nil {
return
}
return net.LookupCNAME(hostname)
}
示例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)
}
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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)
}
示例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()
}