1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00
Files
stackexchange-dnscontrol/models/dns.go
Tom Limoncelli de4455942b Refactor RecordConfig: Add getters/setters (#314)
* Replace RecordConfig.Name and .NameFQDN with getters and setters.
* Replace RecordConfig.Target with getters and setters.
* Eliminate the CombinedTarget concept.
* Add RecordConfig.PopulateFromString to reduce code in all providers.
* encode and decode name.com txt records (#315)
* Replace fmt.Errorf with errors.Errorf
2018-02-15 12:02:50 -05:00

63 lines
1.8 KiB
Go

package models
import (
"encoding/json"
)
// DefaultTTL is applied to any DNS record without an explicit TTL.
const DefaultTTL = uint32(300)
// DNSConfig describes the desired DNS configuration, usually loaded from dnsconfig.js.
type DNSConfig struct {
Registrars []*RegistrarConfig `json:"registrars"`
DNSProviders []*DNSProviderConfig `json:"dns_providers"`
Domains []*DomainConfig `json:"domains"`
RegistrarsByName map[string]*RegistrarConfig `json:"-"`
DNSProvidersByName map[string]*DNSProviderConfig `json:"-"`
}
// FindDomain returns the *DomainConfig for domain query in config.
func (config *DNSConfig) FindDomain(query string) *DomainConfig {
for _, b := range config.Domains {
if b.Name == query {
return b
}
}
return nil
}
// RegistrarConfig describes a registrar.
type RegistrarConfig struct {
Name string `json:"name"`
Type string `json:"type"`
Metadata json.RawMessage `json:"meta,omitempty"`
}
// DNSProviderConfig describes a DNS service provider.
type DNSProviderConfig struct {
Name string `json:"name"`
Type string `json:"type"`
Metadata json.RawMessage `json:"meta,omitempty"`
}
// Nameserver describes a nameserver.
type Nameserver struct {
Name string `json:"name"` // Normalized to a FQDN with NO trailing "."
Target string `json:"target"`
}
// StringsToNameservers constructs a list of *Nameserver structs using a list of FQDNs.
func StringsToNameservers(nss []string) []*Nameserver {
nservers := []*Nameserver{}
for _, ns := range nss {
nservers = append(nservers, &Nameserver{Name: ns})
}
return nservers
}
// Correction is anything that can be run. Implementation is up to the specific provider.
type Correction struct {
F func() error `json:"-"`
Msg string
}