diff --git a/client.go b/client.go index 53df90a9..72ed6d73 100644 --- a/client.go +++ b/client.go @@ -86,7 +86,7 @@ func NewResolver(options ...ClientOption) (*Resolver, error) { func (r *Resolver) Browse(ctx context.Context, service, domain string, entries chan<- *ServiceEntry) error { params := defaultParams(service) if domain != "" { - params.Domain = domain + params.SetDomain(domain) } params.Entries = entries ctx, cancel := context.WithCancel(ctx) @@ -113,7 +113,7 @@ func (r *Resolver) Lookup(ctx context.Context, instance, service, domain string, params := defaultParams(service) params.Instance = instance if domain != "" { - params.Domain = domain + params.SetDomain(domain) } params.Entries = entries ctx, cancel := context.WithCancel(ctx) diff --git a/service.go b/service.go index b6451f19..b60d1aeb 100644 --- a/service.go +++ b/service.go @@ -35,17 +35,12 @@ func (s *ServiceRecord) ServiceTypeName() string { return s.serviceTypeName } -// NewServiceRecord constructs a ServiceRecord. -func NewServiceRecord(instance, service, domain string) *ServiceRecord { - s := &ServiceRecord{ - Instance: instance, - Service: service, - Domain: domain, - serviceName: fmt.Sprintf("%s.%s.", trimDot(service), trimDot(domain)), - } +// Sets the Domain, serviceName and serviceTypeName for a ServiceRecord +func (s *ServiceRecord) SetDomain(domain string) { + s.Domain = domain - // Cache service instance name - if instance != "" { + s.serviceName = fmt.Sprintf("%s.%s.", trimDot(s.Service), trimDot(domain)) + if s.Instance != "" { s.serviceInstanceName = fmt.Sprintf("%s.%s", trimDot(s.Instance), s.ServiceName()) } @@ -55,6 +50,16 @@ func NewServiceRecord(instance, service, domain string) *ServiceRecord { typeNameDomain = trimDot(s.Domain) } s.serviceTypeName = fmt.Sprintf("_services._dns-sd._udp.%s.", typeNameDomain) +} + +// NewServiceRecord constructs a ServiceRecord. +func NewServiceRecord(instance, service, domain string) *ServiceRecord { + s := &ServiceRecord{ + Instance: instance, + Service: service, + } + + s.SetDomain(domain) return s }