mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-11-10 09:12:47 +08:00
Eliminate models.StringsToNameservers() (#1486)
* Eliminate StringsToNameservers() * update comments
This commit is contained in:
parent
e2536ad406
commit
41d994bab6
2 changed files with 9 additions and 17 deletions
|
@ -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()
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue