Skip to content

Commit

Permalink
consider domain names other than .local in lookup/browse
Browse files Browse the repository at this point in the history
  • Loading branch information
florianorben authored and celebdor committed Apr 4, 2019
1 parent c328d57 commit bd3764f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 15 additions & 10 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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
}
Expand Down

0 comments on commit bd3764f

Please sign in to comment.