package server import ( "context" "github.com/grandcat/zeroconf" "github.com/pkg/errors" "github.com/wlynxg/anet" "gitlab.com/wpetit/goweb/logger" ) const ( MDNSService = "_arcast._http._tcp" MDNSDomain = "local." ) func (s *Server) startMDNServer(ctx context.Context) error { logger.Debug(ctx, "starting mdns server") ifaces, err := anet.Interfaces() if err != nil { return errors.WithStack(err) } ips, err := getLANIPv4Addrs() if err != nil { return errors.WithStack(err) } logger.Debug(ctx, "advertising ips", logger.F("ips", ips)) server, err := zeroconf.RegisterProxy(s.instanceID, MDNSService, MDNSDomain, s.port, s.instanceID, ips, []string{}, ifaces) if err != nil { return errors.WithStack(err) } go func() { <-ctx.Done() logger.Debug(ctx, "closing mdns server") server.Shutdown() }() return nil }