From ad6f6e19c21907206b090d170dd55ad612a4e9f2 Mon Sep 17 00:00:00 2001 From: Antoni Segura Puimedon Date: Wed, 13 Mar 2019 12:08:57 +0100 Subject: [PATCH] Allow Registering specifc ServiceEntries This patch allows the library user more control in the registry flow by giving them the chance to pass the ServiceEntries they crafted. --- server.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server.go b/server.go index 86701514..5b8dce58 100644 --- a/server.go +++ b/server.go @@ -23,6 +23,23 @@ const ( multicastRepetitions = 2 ) +func RegisterSvcEntry(entry *ServiceEntry, ifaces []net.Interface) (*Server, error) { + if entry.AddrIPv4 == nil && entry.AddrIPv6 == nil { + return nil, fmt.Errorf("Could not determine host IP addresses") + } + + s, err := newServer(ifaces) + if err != nil { + return nil, err + } + + s.service = entry + go s.mainloop() + go s.probe() + + return s, nil +} + // Register a service by given arguments. This call will take the system's hostname // and lookup IP by that hostname. func Register(instance, service, domain string, port int, text []string, ifaces []net.Interface) (*Server, error) {