From 41d994bab6191126bff0d41db3367f43d08dcb05 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Sun, 24 Apr 2022 09:08:40 -0400 Subject: [PATCH] Eliminate models.StringsToNameservers() (#1486) * Eliminate StringsToNameservers() * update comments --- integrationTest/integration_test.go | 3 ++- models/dns.go | 23 +++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index 36075e8a0..910924818 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -330,7 +330,8 @@ func TestDualProviders(t *testing.T) { run() // add bogus nameservers dc.Records = []*models.RecordConfig{} - dc.Nameservers = append(dc.Nameservers, models.StringsToNameservers([]string{"ns1.example.com", "ns2.example.com"})...) + nslist, _ := models.ToNameservers([]string{"ns1.example.com", "ns2.example.com"}) + dc.Nameservers = append(dc.Nameservers, nslist...) nameservers.AddNSRecords(dc) t.Log("Adding nameservers from another provider") run() diff --git a/models/dns.go b/models/dns.go index 525b60795..6fa4b5c62 100644 --- a/models/dns.go +++ b/models/dns.go @@ -43,32 +43,23 @@ type DNSProviderConfig struct { Metadata json.RawMessage `json:"meta,omitempty"` } -// FIXME(tal): In hindsight, the Nameserver struct is overkill. We -// could have just used []string. Now every provider calls StringsToNameservers -// and ever user calls StringsToNameservers. We should refactor this -// some day. https://github.com/StackExchange/dnscontrol/issues/577 - // Nameserver describes a nameserver. type Nameserver struct { Name string `json:"name"` // Normalized to a FQDN with NO trailing "." // NB(tlim): DomainConfig.Nameservers are stored WITH a trailing "." (Sorry!) } +// FIXME(tal): In hindsight the Nameserver struct is overkill. We +// could have just used string. Currently there are very few places +// that refer to the .Name field directly. All new code should use +// ToNameservers/ToNameserversStripTD and NameserversToStrings to make +// future refactoring easier. See +// https://github.com/StackExchange/dnscontrol/issues/577 + func (n *Nameserver) String() string { return n.Name } -// StringsToNameservers constructs a list of *Nameserver structs using a list of FQDNs. -// Deprecated. Please use ToNameservers, or maybe ToNameserversStripTD instead. -// See https://github.com/StackExchange/dnscontrol/issues/491 -func StringsToNameservers(nss []string) []*Nameserver { - nservers := []*Nameserver{} - for _, ns := range nss { - nservers = append(nservers, &Nameserver{Name: ns}) - } - return nservers -} - // ToNameservers turns a list of strings into a list of Nameservers. // It is an error if any string has a trailing dot. Either remove the // trailing dot before you call this or (much preferred) use ToNameserversStripTD.