Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APICredentials ¶
type APICredentials struct {
// Email is the E-Mail address that is used for accessing the DNSimple API
Email string
// Token is the API token used for accessing the DNSimple API
Token string
}
APICredentials contains the credentials for accessing the DNSimple API.
func NewAPICredentials ¶
func NewAPICredentials(email, token string) (APICredentials, error)
NewAPICredentials creates a new credentials model from the given e-mail address and API token. If the given parameters are invalid an error will be returned.
type CredentialDeleter ¶
type CredentialDeleter interface {
// DeleteCredentials deletes any saved credentials.
DeleteCredentials() error
}
CredentialDeleter deletes credentials.
type CredentialProvider ¶
type CredentialProvider interface {
// GetCredentials returns any stored credentials if there are any.
// Otherwise GetCredentials will return an error.
GetCredentials() (APICredentials, error)
}
CredentialProvider returns credentials.
type CredentialSaver ¶
type CredentialSaver interface {
// SaveCredentials saves the given credentials.
SaveCredentials(credentials APICredentials) error
}
CredentialSaver persists credentials.
type CredentialStore ¶
type CredentialStore interface {
CredentialProvider
CredentialSaver
CredentialDeleter
}
CredentialStore provides functions for reading and persisting APICredentials.
type DNSClient ¶
type DNSClient interface {
// UpdateRecord update the DNS record with the given id.
UpdateRecord(domain string, id string, opts *dnsimple.ChangeRecord) (string, error)
// GetRecords returns all DNS records for the given domain.
GetRecords(domain string) ([]dnsimple.Record, error)
// GetDomains returns a list of domain.
GetDomains() ([]dnsimple.Domain, error)
// CreateRecord creates a new DNS record for the given domain.
CreateRecord(domain string, opts *dnsimple.ChangeRecord) (string, error)
// DestroyRecord deletes the DNS record with the given id.
DestroyRecord(domain string, id string) error
}
DNSClient provides functions for updating DNS records.
func NewDNSClient ¶
func NewDNSClient(credentials APICredentials) (DNSClient, error)
NewDNSClient creates a new DNS client instance for the given credentials.
Example ¶
Create a new DNS client instance and fetch all domain names.
// assemble the API credentials
credentials := APICredentials{"john.doe@example.com", "ApItOken"}
// create a new DNS client
dnsClient, clientError := NewDNSClient(credentials)
if clientError != nil {
fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
os.Exit(1)
}
// fetch all available domains
domains, domainsError := dnsClient.GetDomains()
if domainsError != nil {
fmt.Fprintf(os.Stderr, "Unable to fetch domains: %s", domainsError.Error())
os.Exit(1)
}
// print domain names to stdout
for _, domain := range domains {
fmt.Fprintf(os.Stdout, "%s\n", domain.Name)
}
type DNSEditor ¶
type DNSEditor struct {
// contains filtered or unexported fields
}
DNSEditor updates DNSimple domain records.
func (*DNSEditor) CreateSubdomain ¶
CreateSubdomain creates an address record for the given domain
func (*DNSEditor) DeleteSubdomain ¶
DeleteSubdomain deletes the address record of the given domain
type DNSInfoProvider ¶
type DNSInfoProvider interface {
// GetDomainNames returns a list of domain names.
// Returns an error if the domain names cannot be fetched.
GetDomainNames() ([]string, error)
// GetDomainRecords returns all DNS records for the given domain.
// Returns an error of the DNS records cannot be fetched or the
// given domain was not found.
GetDomainRecords(domain string) ([]dnsimple.Record, error)
// GetSubdomainRecord returns the DNS record for the given domain, subdomain and record type.
// Returns an error if no DNS record was found.
GetSubdomainRecord(domain, subdomain, recordType string) (dnsimple.Record, error)
// GetSubdomainRecords returns a list of all available DNS records for the
// given domain and subdomain.
GetSubdomainRecords(domain, subdomain string) ([]dnsimple.Record, error)
}
The DNSInfoProvider interface offer DNS info functions.
func NewDNSInfoProvider ¶
func NewDNSInfoProvider(client DNSClient) DNSInfoProvider
NewDNSInfoProvider creates a new DNS info provider instance.
Example ¶
Create a new DNS info provider.
// create a DNS client
credentials := APICredentials{"john.doe@example.com", "ApItOken"}
dnsClient, clientError := NewDNSClient(credentials)
if clientError != nil {
fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
os.Exit(1)
}
// create a new DNS info provider instance
dnsInfoProvider := NewDNSInfoProvider(dnsClient)
// get all domain names
domainNames, domainNamesError := dnsInfoProvider.GetDomainNames()
if domainNamesError != nil {
fmt.Fprintf(os.Stderr, "Unable to fetch domain names: %s", domainNamesError.Error())
os.Exit(1)
}
// print a list all domain names
for _, domainName := range domainNames {
fmt.Fprintf(os.Stdout, "%s\n", domainName)
}
type DNSRecordCreator ¶
type DNSRecordCreator interface {
// CreateSubdomain creates a new subdomain address record.
CreateSubdomain(domain, subDomainName string, timeToLive int, ip net.IP) error
}
The DNSRecordCreator interface offers functions for creating domain records.
type DNSRecordDeleter ¶
type DNSRecordDeleter interface {
// DeleteSubdomain removes subdomain address record of the given type.
DeleteSubdomain(domain, subDomainName string, recordType string) error
}
The DNSRecordDeleter interface offers functions for creating domain records.
type DNSRecordEditor ¶
type DNSRecordEditor interface {
DNSRecordCreator
DNSRecordUpdater
DNSRecordDeleter
}
The DNSRecordEditor interface provides functions for editing DNS records.
func NewDNSEditor ¶
func NewDNSEditor(client DNSClient, infoProvider DNSInfoProvider) DNSRecordEditor
NewDNSEditor creates an new DNSRecordEditor instance.
Example ¶
Create a new DNS editor instance.
// create a DNS client
credentials := APICredentials{"john.doe@example.com", "ApItOken"}
dnsClient, clientError := NewDNSClient(credentials)
if clientError != nil {
fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
os.Exit(1)
}
// create a new DNS info provider instance
dnsInfoProvider := NewDNSInfoProvider(dnsClient)
// create a new DNS editor instance
dnsEditor := NewDNSEditor(dnsClient, dnsInfoProvider)
// create an DNS A record for www.example.com pointing to 127.0.0.1
domain := "example.com"
subDomainName := "www"
timeToLive := 600
ip := net.ParseIP("127.0.0.1")
createSubdomainError := dnsEditor.CreateSubdomain(domain, subDomainName, timeToLive, ip)
if createSubdomainError != nil {
fmt.Fprintf(os.Stderr, "Failed to create subdomain %s.%s: %s", subDomainName, domain, clientError.Error())
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "Created subdomain %s.%s", subDomainName, domain)