Stop custom Client struct from being exported in Provider
This commit is contained in:
parent
120fee4266
commit
77ddd0389e
32
client.go
32
client.go
@ -6,31 +6,31 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/vultr/govultr"
|
||||
"github.com/libdns/libdns"
|
||||
"github.com/vultr/govultr"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *govultr.Client
|
||||
vultr *govultr.Client
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
func (p *Provider) getClient() error {
|
||||
if p.client == nil {
|
||||
p.client = govultr.NewClient(nil, p.APIToken)
|
||||
if p.client.vultr == nil {
|
||||
p.client.vultr = govultr.NewClient(nil, p.APIToken)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Provider) getDNSEntries(ctx context.Context, domain string) ([]libdns.Record, error) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.client.mutex.Lock()
|
||||
defer p.client.mutex.Unlock()
|
||||
|
||||
p.getClient()
|
||||
|
||||
var records []libdns.Record
|
||||
dns_entries, err := p.client.DNSRecord.List(ctx, domain)
|
||||
dns_entries, err := p.client.vultr.DNSRecord.List(ctx, domain)
|
||||
if err != nil {
|
||||
return records, err
|
||||
}
|
||||
@ -50,12 +50,12 @@ func (p *Provider) getDNSEntries(ctx context.Context, domain string) ([]libdns.R
|
||||
}
|
||||
|
||||
func (p *Provider) addDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.client.mutex.Lock()
|
||||
defer p.client.mutex.Unlock()
|
||||
|
||||
p.getClient()
|
||||
|
||||
err := p.client.DNSRecord.Create(ctx, domain, record.Type, record.Name, record.Value, int(record.TTL.Seconds()), 0)
|
||||
err := p.client.vultr.DNSRecord.Create(ctx, domain, record.Type, record.Name, record.Value, int(record.TTL.Seconds()), 0)
|
||||
if err != nil {
|
||||
return record, err
|
||||
}
|
||||
@ -64,12 +64,12 @@ func (p *Provider) addDNSRecord(ctx context.Context, domain string, record libdn
|
||||
}
|
||||
|
||||
func (p *Provider) removeDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.client.mutex.Lock()
|
||||
defer p.client.mutex.Unlock()
|
||||
|
||||
p.getClient()
|
||||
|
||||
err := p.client.DNSRecord.Delete(ctx, domain, record.ID)
|
||||
err := p.client.vultr.DNSRecord.Delete(ctx, domain, record.ID)
|
||||
if err != nil {
|
||||
return record, err
|
||||
}
|
||||
@ -78,8 +78,8 @@ func (p *Provider) removeDNSRecord(ctx context.Context, domain string, record li
|
||||
}
|
||||
|
||||
func (p *Provider) updateDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.client.mutex.Lock()
|
||||
defer p.client.mutex.Unlock()
|
||||
|
||||
p.getClient()
|
||||
|
||||
@ -96,7 +96,7 @@ func (p *Provider) updateDNSRecord(ctx context.Context, domain string, record li
|
||||
RecordID: id,
|
||||
}
|
||||
|
||||
err = p.client.DNSRecord.Update(ctx, domain, &entry)
|
||||
err = p.client.vultr.DNSRecord.Update(ctx, domain, &entry)
|
||||
if err != nil {
|
||||
return record, err
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
// Provider implements the libdns interfaces for Vultr
|
||||
// Adapted from libdns/digitalocean to work with the Vultr API
|
||||
type Provider struct {
|
||||
Client
|
||||
client Client
|
||||
// APIToken is the Vultr API token
|
||||
// see https://my.vultr.com/settings/#settingsapi
|
||||
APIToken string `json:"auth_token"`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user