micro/go-micro · error

hostName %q is not a fully-qualified domain name: %v

Error message

hostName %q is not a fully-qualified domain name: %v

What it means

NewMDNSService validates the (explicit or auto-detected) hostName with validateFQDN; a non-empty hostName that does not end in a period (or is otherwise invalid) produces this wrapped error. The %v carries the specific validation failure.

Source

Thrown at internal/util/mdns/zone.go:94

	// Set default domain
	if domain == "" {
		domain = "local."
	}
	if err := validateFQDN(domain); err != nil {
		return nil, fmt.Errorf("domain %q is not a fully-qualified domain name: %v", domain, err)
	}

	// Get host information if no host is specified.
	if hostName == "" {
		var err error
		hostName, err = os.Hostname()
		if err != nil {
			return nil, fmt.Errorf("could not determine host: %v", err)
		}
		hostName = fmt.Sprintf("%s.", hostName)
	}
	if err := validateFQDN(hostName); err != nil {
		return nil, fmt.Errorf("hostName %q is not a fully-qualified domain name: %v", hostName, err)
	}

	if len(ips) == 0 {
		var err error
		ips, err = net.LookupIP(trimDot(hostName))
		if err != nil {
			// Try appending the host domain suffix and lookup again
			// (required for Linux-based hosts)
			tmpHostName := fmt.Sprintf("%s%s", hostName, domain)

			ips, err = net.LookupIP(trimDot(tmpHostName))

			if err != nil {
				return nil, fmt.Errorf("could not determine host IP addresses for %s", hostName)
			}
		}
	}
	for _, ip := range ips {

View on GitHub (pinned to 24529f1404)

Solutions

  1. Ensure hostName ends in '.': hostName = strings.TrimSuffix(hostName, ".") + "."
  2. Leave hostName empty to let NewMDNSService auto-detect and correctly append the dot
  3. Normalize hostName during config load with the same rule as validateFQDN

Example fix

// before
svc, err := NewMDNSService("myapp", "_http._tcp", "local.", "myhost.local", 8080, ips, nil)
// after
svc, err := NewMDNSService("myapp", "_http._tcp", "local.", "myhost.local.", 8080, ips, nil)
Defensive patterns

Strategy: validation

Validate before calling

func normalizeHostName(h string) string {
	if h == "" { return "" } // let the library auto-detect
	if !strings.HasSuffix(h, ".") { return h + "." }
	return h
}
// hostName = normalizeHostName(cfg.HostName)

Type guard

func isValidHostName(h string) bool { return len(h) > 0 && h[len(h)-1] == '.' }

Try / catch

svc, err := NewMDNSService(instance, service, domain, hostName, port, ips, txt)
if err != nil {
	if strings.Contains(err.Error(), "hostName") && strings.Contains(err.Error(), "fully-qualified") {
		return fmt.Errorf("hostname must end in a trailing dot, e.g. 'myhost.local.': %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Passing hostName like "myhost.local" (no trailing dot) or "" where the auto-detected path was skipped; directly supplying a hostName that fails validateFQDN after NewMDNSService defaults were applied.

Common situations: Building hostName from config values that omit the trailing dot; concatenating hostname and domain in the wrong order so the dot is lost; migrations from libraries that accept dot-less hostnames.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/45aa81585402b82f. Report an issue: GitHub.