Documentation ¶
Overview ¶
Package mdns provides Instancer and Registrar implementations for mDNS. mDNS or Multicast DNS can be used to discover services on the local network without the use of an authoritative DNS server. This enables peer-to-peer discovery. It is important to note that many networks restrict the use of multicasting, which prevents mDNS from functioning. Notably, multicast cannot be used in any sort of cloud, or shared infrastructure environment. However it works well in most office, home, or private infrastructure environments.
Example ¶
package main import ( "fmt" "io" "io/ioutil" "net" "os" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "github.com/go-kit/kit/sd" ) func main() { var ( serverName = "/services/kit-mdns" instance = "127.0.0.1:8080" port = 8080 logger = log.NewLogfmtLogger(os.Stdout) ) // Build the registrar service := Service{ Instance: instance, Service: serverName, Port: port, Ips: []net.IP{net.IPv4(127, 0, 0, 1)}, // Just for test } registrar, err := NewRegistrar(service, logger) if err != nil { fmt.Println(err) return } // Register my instance registrar.Register() defer registrar.Deregister() // Build the instancer instancer, err := NewInstancer(serverName, InstancerOptions{}, logger) if err != nil { fmt.Println(err) return } // Build the endpoint endpointer := sd.NewEndpointer(instancer, fakeFactory, logger) _, err = endpointer.Endpoints() if err != nil { fmt.Println(err) } } func fakeFactory(instance string) (endpoint.Endpoint, io.Closer, error) { // Print instance fmt.Println(instance) return endpoint.Nop, ioutil.NopCloser(nil), nil }
Output: 127.0.0.1:8080
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Instancer ¶
type Instancer struct {
// contains filtered or unexported fields
}
Instancer an mDns instancer. It will flushes the cache at intervals.
func NewInstancer ¶
NewInstancer returns an mDNS instancer.
func (*Instancer) Deregister ¶
Deregister implements Instancer.
type InstancerOptions ¶
type InstancerOptions struct { RefreshInterval time.Duration // Refresh intervals, default 3 second Domain string // Lookup domain, default "local" LookupTimeout time.Duration // Lookup timeout, default 1 second Interface *net.Interface // Multicast interface to use WantUnicastResponse bool // Unicast response desired, as per 5.4 in RFC }
InstancerOptions is used to customize how a Lookup is performed.
type Registrar ¶
type Registrar struct {
// contains filtered or unexported fields
}
Registrar is used to listen for mDNS queries and respond if we have a matching local record.
func NewRegistrar ¶
NewRegistrar is used to create a new registrar from a service config.
func (*Registrar) Deregister ¶
func (registrar *Registrar) Deregister()
Deregister is used to shutdown the listener.