hostname

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostname provides best-effort, stable naming helpers intended specifically for configuring mDNS advertisements.

This package does NOT attempt to discover or validate network identity. Instead, it produces deterministic, mDNS-safe name inputs that higher-level mDNS libraries (such as github.com/hashicorp/mdns) can probe, de-duplicate, and advertise according to RFC 6762.

Design principles:

  • Never fail: all exported functions always return a usable value.
  • No networking: no DNS, no sockets, no interface inspection.
  • Stable identity: names remain consistent across process restarts.
  • mDNS-first: behavior aligns with common Bonjour / Avahi conventions.
  • Minimal scope: collision detection and resolution are delegated to mDNS.

Hostnames vs Service Instance Names:

mDNS distinguishes between a host name (used for A/AAAA records) and a service instance name (human-facing, shown in UIs). These identifiers have different stability and collision expectations and are treated separately by this package.

  • Host(): returns a stable, mDNS-safe host label (without ".local."). This name is intended for A/AAAA records and should change rarely.

  • Base(): returns the short, sanitized base hostname without suffixes or domains. This is used as a building block for other names.

  • ServiceInstance(): returns a human-friendly service instance name suitable for direct use with mDNS service advertisements. Collisions are expected and resolved by the mDNS implementation.

Name Sources and Stability:

Names are resolved in the following order:

  1. Explicit override via environment variable (e.g. MYAPP_HOSTNAME)
  2. Operating system hostname (short form, best-effort)
  3. Application-defined fallback name

To reduce collisions when multiple instances are present on the same link, host names include a stable per-machine suffix derived from a system identifier or a persisted random value.

What this package intentionally does NOT do:

  • Append ".local." to names
  • Perform RFC 6762 probing or conflict resolution
  • Inspect network interfaces or IP addresses
  • Guarantee global uniqueness
  • Enforce service naming policies

These responsibilities belong to the mDNS implementation layer.

Typical usage:

host := hostname.Host()
instance := hostname.ServiceInstance("My Service")

// Pass host and instance to an mDNS library for advertisement.

This package is safe to use in long-running services, containers, and multi-instance environments where network identity may be incomplete or unavailable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base

func Base() string

Base returns the short, sanitized base hostname without suffixes or domains. It checks (in order): environment variable, OS hostname, or a default value.

func Identity

func Identity() string

Identity returns the stable, canonical host identity used as the base for mDNS hostnames. When a hostname is explicitly configured (via env var or OS hostname), returns just the base. Otherwise appends a stable unique suffix to disambiguate: <base>-<unique-id> (e.g., "dirio-s3-abc123").

func SetStateDir

func SetStateDir(dir string)

SetStateDir configures the directory where hostname state files are stored. startup.Init calls this with the resolved data directory.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL