mdns

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

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

func (config *Config) Apply(app *govalin.App)

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

func (config *Config) Hostname(hostname string) *Config

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

func (config *Config) InstanceName(name string) *Config

InstanceName sets the human-readable service instance name shown in discovery tooling. Defaults to the executable base name.

func (*Config) Interfaces

func (config *Config) Interfaces(interfaces ...string) *Config

Interfaces restricts advertisement to the named network interfaces (e.g. "en0"). Defaults to all multicast-capable interfaces (auto-detected).

func (*Config) Name

func (config *Config) Name() string

func (*Config) OnInit

func (config *Config) OnInit(govalinConfig *govalin.Config)

OnInit validates the configuration (fatal on misconfiguration) and registers the shutdown hook that withdraws the service via goodbye packets.

func (*Config) ServiceType

func (config *Config) ServiceType(serviceType string) *Config

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".

func (*Config) Text

func (config *Config) Text(text map[string]string) *Config

Text sets the TXT record key/value pairs advertised with the service. Each `key=value` entry must fit DNS-SD size limits; an oversized entry is fatal at OnInit. Defaults to {path: /}.

Jump to

Keyboard shortcuts

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