func getFqdn() (string, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return "", err
	}

	ips, err := net.LookupIP(hostname)
	if err != nil {
		// Return the system hostname if we can't look up the IP address.
		return hostname, nil
	}

	lookup := func(ipStr encoding.TextMarshaler) (string, error) {
		ip, err := ipStr.MarshalText()
		if err != nil {
			return "", err
		}
		hosts, err := net.LookupAddr(string(ip))
		if err != nil || len(hosts) == 0 {
			return "", err
		}
		return hosts[0], nil
	}

	for _, addr := range ips {
		if ip := addr.To4(); ip != nil {
			if fqdn, err := lookup(ip); err == nil {
				return fqdn, nil
			}

		}

		if ip := addr.To16(); ip != nil {
			if fqdn, err := lookup(ip); err == nil {
				return fqdn, nil
			}

		}
	}
	return hostname, nil
}
func getFqdn() (string, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return "", err
	}

	ips, err := net.LookupIP(hostname)
	if err != nil {
		
		return hostname, nil
	}

	lookup := func(ipStr encoding.TextMarshaler) (string, error) {
		ip, err := ipStr.MarshalText()
		if err != nil {
			return "", err
		}
		hosts, err := net.LookupAddr(string(ip))
		if err != nil || len(hosts) == 0 {
			return "", err
		}
		return hosts[0], nil
	}

	for _, addr := range ips {
		if ip := addr.To4(); ip != nil {
			if fqdn, err := lookup(ip); err == nil {
				return fqdn, nil
			}

		}

		if ip := addr.To16(); ip != nil {
			if fqdn, err := lookup(ip); err == nil {
				return fqdn, nil
			}

		}
	}
	return hostname, nil
}
func getFqdn ( ) ( string , error ) { hostname , err := os . Hostname ( ) if err != nil { return " " , err } ips , err := net . LookupIP ( hostname ) if err != nil { // Return the system hostname if we can't look up the IP address. return hostname , nil } lookup := func ( ipStr encoding . TextMarshaler ) ( string , error ) { ip , err := ipStr . MarshalText ( ) if err != nil { return " " , err } hosts , err := net . LookupAddr ( string ( ip ) ) if err != nil || len ( hosts ) == 0 { return " " , err } return hosts [ 0 ] , nil } for _ , addr := range ips { if ip := addr . To4 ( ) ; ip != nil { if fqdn , err := lookup ( ip ) ; err == nil { return fqdn , nil } } if ip := addr . To16 ( ) ; ip != nil { if fqdn , err := lookup ( ip ) ; err == nil { return fqdn , nil } } } return hostname , nil }
// getFqdn returns a FQDN if it's possible, otherwise falls back to hostname.
getFqdn returns a FQDN if it s possible otherwise falls back to hostname .