Documentation
¶
Overview ¶
Package dotlocal turns an http.Handler into a named service on the local network: it binds a port, advertises <Name>.local over mDNS (correctly scoped across every LAN on a multi-homed host), and serves with graceful shutdown — the companion to the go:embed'd local-web-app pattern.
The common case is one call:
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
err := dotlocal.Run(ctx, dotlocal.Config{Name: "fwrd", Handler: app})
To reach it at a bare http://<Name>.local (port 80) without a privileged bind or a host :80 collision, see the port80 subpackage (a separate, root-only step); advertise its alias IPs with mdns.AdvertiseScoped.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Name string // bare label, e.g. "fwrd" → advertised as fwrd.local
Handler http.Handler // the service to expose (e.g. your go:embed'd app)
Addr string // bind address; default "0.0.0.0:8080"
Advertise bool // advertise <Name>.local over mDNS
Interfaces []string // restrict mDNS to these interfaces; empty = auto LAN
Info string // mDNS TXT text; default "<Name> (dotlocal)"
// OnReady, if set, is called once the listener is bound (and mDNS started),
// before serving. Use it to log the reachable URLs. AdvertiseErr is non-nil
// if mDNS failed — serving continues regardless.
OnReady func(Ready)
}
Config configures Run. Only Name and Handler are required.
type Ready ¶
type Ready struct {
Addr string // the actual listen address
Name string // "<Name>.local" when advertising, else ""
Targets []string // advertised "iface=ip" pairs, when advertising
AdvertiseErr error // non-nil if mDNS advertising failed (non-fatal)
}
Ready reports the bound state to the OnReady callback.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
dotlocal
command
Command dotlocal exposes the dotlocal library to non-Go services: give any local HTTP server a <name>.local address on a standard port, from a shell script, an installer, or a service manager.
|
Command dotlocal exposes the dotlocal library to non-Go services: give any local HTTP server a <name>.local address on a standard port, from a shell script, an installer, or a service manager. |
|
examples
|
|
|
embedserve
command
Command embedserve is a minimal example of the dotlocal pattern: a go:embed'd web app served as a named LAN service reachable at http://embedserve.local.
|
Command embedserve is a minimal example of the dotlocal pattern: a go:embed'd web app served as a named LAN service reachable at http://embedserve.local. |
|
internal
|
|
|
lan
Package lan holds the small LAN/DNS primitives shared by the public packages, so there is one definition of each rather than a copy drifting in every package.
|
Package lan holds the small LAN/DNS primitives shared by the public packages, so there is one definition of each rather than a copy drifting in every package. |
|
Package mdns advertises a service on the local network over multicast DNS, so it is reachable at a stable <name>.local address without DNS, a hosts entry, or a static IP.
|
Package mdns advertises a service on the local network over multicast DNS, so it is reachable at a stable <name>.local address without DNS, a hosts entry, or a static IP. |
|
Package port80 makes a service reachable at http://<name>.local on one or more standard public ports (80 by default, optionally 443 as well) without binding a privileged port and without colliding with any server the host already runs on those ports.
|
Package port80 makes a service reachable at http://<name>.local on one or more standard public ports (80 by default, optionally 443 as well) without binding a privileged port and without colliding with any server the host already runs on those ports. |
Click to show internal directories.
Click to hide internal directories.