dnsprovider

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package dnsprovider abstracts DNS record management across providers.

Cloudflare is implemented today; the Provider interface and the registry keep room for Aliyun / DNSPod / Route53 without touching callers. Each record carries a Comment field — that is where a record's "note" lives, mapping onto Cloudflare's native per-record comment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalCreds

func MarshalCreds(v any) ([]byte, error)

MarshalCreds is a small helper for callers building credential blobs.

func Names

func Names() []string

Names returns the registered provider names.

func Register

func Register(name string, f Factory)

Register makes a provider available by name.

Types

type Cloudflare

type Cloudflare struct {
	// contains filtered or unexported fields
}

Cloudflare implements Provider against the Cloudflare API v4.

func (*Cloudflare) CreateRecord

func (c *Cloudflare) CreateRecord(ctx context.Context, zoneID string, r Record) (Record, error)

func (*Cloudflare) DeleteRecord

func (c *Cloudflare) DeleteRecord(ctx context.Context, zoneID, recordID string) error

func (*Cloudflare) ListRecords

func (c *Cloudflare) ListRecords(ctx context.Context, zoneID string) ([]Record, error)

func (*Cloudflare) ListZones

func (c *Cloudflare) ListZones(ctx context.Context) ([]Zone, error)

func (*Cloudflare) UpdateRecord

func (c *Cloudflare) UpdateRecord(ctx context.Context, zoneID string, r Record) (Record, error)

func (*Cloudflare) VerifyZone

func (c *Cloudflare) VerifyZone(ctx context.Context, zoneID string) (string, error)

type DNSPod

type DNSPod struct {
	// contains filtered or unexported fields
}

DNSPod implements Provider against the legacy DNSPod login-token API (https://dnsapi.cn). Zones are identified by their DNSPod numeric domain_id, which callers store as the domain's ZoneID.

func (*DNSPod) CreateRecord

func (d *DNSPod) CreateRecord(ctx context.Context, zoneID string, r Record) (Record, error)

func (*DNSPod) DeleteRecord

func (d *DNSPod) DeleteRecord(ctx context.Context, zoneID, recordID string) error

func (*DNSPod) ListRecords

func (d *DNSPod) ListRecords(ctx context.Context, zoneID string) ([]Record, error)

func (*DNSPod) ListZones

func (d *DNSPod) ListZones(ctx context.Context) ([]Zone, error)

func (*DNSPod) UpdateRecord

func (d *DNSPod) UpdateRecord(ctx context.Context, zoneID string, r Record) (Record, error)

func (*DNSPod) VerifyZone

func (d *DNSPod) VerifyZone(ctx context.Context, zoneID string) (string, error)

type Factory

type Factory func(credsJSON []byte) (Provider, error)

Factory builds a Provider from a decrypted JSON credentials blob.

type Provider

type Provider interface {
	// ListZones returns every zone (domain) the credentials can manage.
	ListZones(ctx context.Context) ([]Zone, error)
	ListRecords(ctx context.Context, zoneID string) ([]Record, error)
	CreateRecord(ctx context.Context, zoneID string, r Record) (Record, error)
	UpdateRecord(ctx context.Context, zoneID string, r Record) (Record, error)
	DeleteRecord(ctx context.Context, zoneID, recordID string) error
	// VerifyZone confirms the credentials can access the zone and returns its name.
	VerifyZone(ctx context.Context, zoneID string) (string, error)
}

Provider is the DNS backend contract.

func New

func New(name string, credsJSON []byte) (Provider, error)

New constructs a provider by name from its credentials JSON.

type Record

type Record struct {
	ID       string `json:"id"`
	Type     string `json:"type"` // A, AAAA, CNAME, TXT, MX, ...
	Name     string `json:"name"`
	Content  string `json:"content"`
	TTL      int    `json:"ttl"`
	Proxied  bool   `json:"proxied"`
	Comment  string `json:"comment"` // the per-record note
	Priority *int   `json:"priority,omitempty"`
}

Record is a provider-agnostic DNS record.

type Zone

type Zone struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Zone is a DNS zone (domain) visible to the credentials.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL