Documentation ¶
Overview ¶
Package dnssrv defines some implementations for a dns based service discovery
Index ¶
Examples ¶
Constants ¶
View Source
const Namespace = "dns"
Namespace is the key for the dns sd module
Variables ¶
View Source
var DefaultLookup = net.LookupSRV
DefaultLookup is the function used for the DNS resolution
View Source
var TTL = 30 * time.Second
TTL is the duration of the cached data
Functions ¶
func NewDetailed ¶
func NewDetailed(name string, lookup lookup, ttl time.Duration) sd.Subscriber
NewDetailed creates a DNS subscriber with the received values
Example ¶
srvSet := []*net.SRV{ { Port: 90, Target: "foobar", Weight: 2, }, { Port: 90, Target: "127.0.0.1", Weight: 2, }, { Port: 80, Target: "127.0.0.1", Weight: 2, }, { Port: 81, Target: "127.0.0.1", Weight: 4, }, { Port: 82, Target: "127.0.0.1", Weight: 10, Priority: 2, }, { Port: 83, Target: "127.0.0.1", }, } lookupFunc := func(service, proto, name string) (cname string, addrs []*net.SRV, err error) { return "cname", srvSet, nil } s := NewDetailed("some.example.tld", lookupFunc, 10*time.Second) hosts, err := s.Hosts() if err != nil { fmt.Println("Getting the hosts:", err.Error()) return } for _, h := range hosts { fmt.Println(h) }
Output: http://127.0.0.1:81 http://127.0.0.1:81 http://127.0.0.1:80 http://127.0.0.1:90 http://foobar:90
func Register ¶
func Register() error
Register registers the dns sd subscriber factory under the name defined by Namespace
Example ¶
if err := Register(); err != nil { fmt.Println("registering the dns module:", err.Error()) return } srvSet := []*net.SRV{ { Port: 90, Target: "foobar", Weight: 2, }, { Port: 90, Target: "127.0.0.1", Weight: 2, }, { Port: 80, Target: "127.0.0.1", Weight: 2, }, { Port: 81, Target: "127.0.0.1", Weight: 4, }, { Port: 82, Target: "127.0.0.1", Weight: 10, Priority: 2, }, { Port: 83, Target: "127.0.0.1", }, } DefaultLookup = func(service, proto, name string) (cname string, addrs []*net.SRV, err error) { return "cname", srvSet, nil } s := sd.GetRegister().Get(Namespace)(&config.Backend{Host: []string{"some.example.tld"}, SD: Namespace}) hosts, err := s.Hosts() if err != nil { fmt.Println("Getting the hosts:", err.Error()) return } for _, h := range hosts { fmt.Println(h) }
Output: http://127.0.0.1:81 http://127.0.0.1:81 http://127.0.0.1:80 http://127.0.0.1:90 http://foobar:90
func SubscriberFactory ¶
func SubscriberFactory(cfg *config.Backend) sd.Subscriber
SubscriberFactory builds a DNS_SRV Subscriber with the received config
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.