From 3cdba6c2b1341d50b3cb5ae2aef020aff2373b51 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 20:56:40 +0000 Subject: [PATCH] feat(service): add documented options alias Co-Authored-By: Virgil --- service.go | 11 ++++++++++- service_test.go | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index 9ec2352..4c2531a 100644 --- a/service.go +++ b/service.go @@ -68,9 +68,18 @@ type ServiceOptions struct { TreeRootCheckInterval time.Duration } +// Options is the documented constructor shape for NewService. +// +// service := dns.NewService(dns.Options{ +// Records: map[string]dns.NameRecords{ +// "gateway.charon.lthn": {A: []string{"10.10.10.10"}}, +// }, +// }) +type Options = ServiceOptions + // NewService builds a DNS service from cached records and optional discovery hooks. // -// service := dns.NewService(dns.ServiceOptions{ +// service := dns.NewService(dns.Options{ // Records: map[string]dns.NameRecords{ // "gateway.charon.lthn": {A: []string{"10.10.10.10"}}, // }, diff --git a/service_test.go b/service_test.go index 6d3d6ae..b5d88d7 100644 --- a/service_test.go +++ b/service_test.go @@ -54,6 +54,24 @@ func TestServiceResolveUsesExactNameBeforeWildcard(t *testing.T) { } } +func TestServiceOptionsAliasBuildsService(t *testing.T) { + service := NewService(Options{ + Records: map[string]NameRecords{ + "gateway.charon.lthn": { + A: []string{"10.10.10.10"}, + }, + }, + }) + + result, ok := service.ResolveAddress("gateway.charon.lthn") + if !ok { + t.Fatal("expected service constructed from Options alias to resolve") + } + if len(result.Addresses) != 1 || result.Addresses[0] != "10.10.10.10" { + t.Fatalf("unexpected resolve result from Options alias: %#v", result.Addresses) + } +} + func TestServiceResolveUsesMostSpecificWildcard(t *testing.T) { service := NewService(ServiceOptions{ Records: map[string]NameRecords{ -- 2.45.3