Documentation
¶
Overview ¶
Package mdns provides an opt-in GOVALIN plugin that advertises the running server on the local network as a DNS-SD `_http._tcp` service over multicast DNS (Bonjour/Zeroconf).
Once registered the app becomes resolvable (`<host>.local`) and browsable with zero configuration via Safari's Bonjour list, `dns-sd -B _http._tcp` (macOS) or `avahi-browse -a` (Linux). The plugin only advertises — it does not browse or discover other services.
The mDNS/brutella dependency is isolated to this package per the plugin complexity boundary; GOVALIN core never imports it.
Failure handling ¶
Failure handling is deliberately asymmetric:
- Misconfiguration (an invalid or non-`_tcp` service type, oversized TXT entries) is validated in OnInit and is fatal, consistent with the cors plugin.
- Runtime registration/broadcast failure (no multicast route, blocked UDP 5353, a container without host networking) is non-fatal — the HTTP server keeps serving and an actionable warning is logged.
Docker ¶
Multicast typically does not cross the default Docker bridge network, so mDNS advertisement will silently reach nothing there. Run the container with host networking (`docker run --network host`) to let mDNS work.
Index ¶
- type Config
- func (config *Config) Apply(app *govalin.App)
- func (config *Config) Hostname(hostname string) *Config
- func (config *Config) InstanceName(name string) *Config
- func (config *Config) Interfaces(interfaces ...string) *Config
- func (config *Config) Name() string
- func (config *Config) OnInit(govalinConfig *govalin.Config)
- func (config *Config) ServiceType(serviceType string) *Config
- func (config *Config) Text(text map[string]string) *Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds the mDNS advertisement configuration. Construct it with New and adjust it with the chainable setters before handing it to config.Plugin.
func New ¶
func New() *Config
New creates an mDNS plugin with zero-config defaults:
- instance name = executable base name
- service type = _http._tcp
- hostname = <os-hostname>.local
- interfaces = all multicast-capable interfaces (auto-detected)
- TXT = {path: /}
Every default is overridable via the chainable setters. New takes no required arguments.
func (*Config) Apply ¶
Apply advertises the service on the network. The listener is already bound by the time Apply runs, so the bound port is read from App.Port(). Runtime failures are non-fatal: they log an actionable warning and leave the HTTP server untouched.
func (*Config) Hostname ¶
Hostname sets the host the service resolves to. A trailing ".local" is optional and normalized away internally. Defaults to "<os-hostname>.local".
func (*Config) InstanceName ¶
InstanceName sets the human-readable service instance name shown in discovery tooling. Defaults to the executable base name.
func (*Config) Interfaces ¶
Interfaces restricts advertisement to the named network interfaces (e.g. "en0"). Defaults to all multicast-capable interfaces (auto-detected).
func (*Config) OnInit ¶
OnInit validates the configuration (fatal on misconfiguration) and registers the shutdown hook that withdraws the service via goodbye packets.
func (*Config) ServiceType ¶
ServiceType sets the DNS-SD service type in full `_service._tcp` form (e.g. "_http._tcp"). The transport is fixed at `_tcp`; any other value is fatal at OnInit. Defaults to "_http._tcp".