ddns

package module
v0.0.0-...-99e743a Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AutomaticTTL uint = 1
	DefaultTTL   uint = 120
)

Variables

View Source
var (
	// ErrEmptyIDUnsupported happens when an empty ID in the DNS Record
	// has been found. This is not supported yet!
	ErrEmptyIDUnsupported = errors.New("Empty DNS record id is not supported yet")

	// ErrEmptyRecordName is a DNS Record validation error, when the Name field
	// is not setted correctly.
	ErrEmptyRecordName = errors.New("DNS record name url is empty")

	// ErrEmptyRecordContent is a DNS Record validation error, when the Content
	// field is not setted correctly.
	ErrEmptyRecordContent = errors.New("DNS record content is empty")
)
View Source
var (
	// ErrNilHTTPClient happens if the http Client used
	// to make http requests is nil.
	ErrNilHTTPClient = errors.New("http client specified is nil")
)

Functions

func NewRequest

func NewRequest(ctx context.Context, config APIConfig, record Record,
	opts ...Option) (<-chan Result, error)

NewRequest takes API configuration, DNS record to keep update, and optional parameters and returns a channel that will emit Results every time a refresh request will be done. A context.Context can be used to cancel the execution of the refresh.

Types

type APIConfig

type APIConfig struct {
	Email  string
	APIKey string
	ZoneID string
}

APIConfig represent the configuration for CloudFlare API.

func (APIConfig) APIDNSPath

func (conf APIConfig) APIDNSPath(id string) string

APIDNSPath returns the url path to which make the API request.

func (APIConfig) Request

func (conf APIConfig) Request(ctx context.Context, body Record) (*http.Request, error)

Request creates an http Request from a Record object. The generated request can be used to update the DNS record. A context.Context is used in order to cancel the http Request, eventually.

type Option

type Option func(opts *Options)

Option identifies a single option that can be applied to the Options.

func ClientHTTP

func ClientHTTP(cli *http.Client) Option

ClientHTTP specifies which http Client to use to make http requests. Only a non-nil client will be applied.

func Timeout

func Timeout(d time.Duration) Option

Timeout specifies after how much the update must occur. Only durations > 0 will be applied.

type Options

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

Options can be applied to the Request object. They'll be used for every API request made by the daemon.

type Record

type Record struct {
	ID      string     `json:"id",toml:"id"`
	Type    RecordType `json:"type",toml:"type"`
	Name    *url.URL   `json:"name",toml:"name"`
	Content string     `json:"content",toml:"content"`

	TTL     uint `json:"ttl,omitempty",toml:"ttl,omitempty"`
	Proxied bool `json:"proxied,omitempty",toml:"proxied,omitempty"`
}

Record identifies a DNS Record for Cloudflare API. For more informations: https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record

func (Record) Copy

func (r Record) Copy(content string) Record

Copy is a copy-constructor that changes only the content field of the new copied Record object.

func (Record) Validate

func (r Record) Validate() error

Validate checks for errors in the DNS Record object, and returns them in case at least one have been found.

type RecordType

type RecordType int

RecordType identifies the supported DNS record type from Cloudflare API. For more informations: https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record

const (
	A RecordType = iota
	AAAA
	CNAME
	TXT
	SRV
	LOC
	MX
	NS
	SPF
)

func (RecordType) String

func (r RecordType) String() string

type Result

type Result struct {
	Status
	Error error
}

Result is the result of a DDNS refresh request.

type Status

type Status uint

Status identifies the status of a record refresh iteration.

const (
	Unchanged Status = iota
	Success
	APIError
	Error
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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