hdns

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const Endpoint = "https://dns.hetzner.com/api/v1"
View Source
const UserAgent = "hdns-go/" + Version

UserAgent is the value for the library part of the User-Agent header that is sent with each request.

View Source
const Version = "0.3.0"

Variables

This section is empty.

Functions

func IsError

func IsError(err error, code ErrorCode) bool

IsError returns whether err is an API error with the given error code.

Types

type BackoffFunc

type BackoffFunc func(retries int) time.Duration

A BackoffFunc returns the duration to wait before performing the next retry. The retries argument specifies how many retries have already been performed. When called for the first time, retries is 0.

func ConstantBackoff

func ConstantBackoff(d time.Duration) BackoffFunc

ConstantBackoff returns a BackoffFunc which backs off for constant duration d.

func ExponentialBackoff

func ExponentialBackoff(b float64, d time.Duration) BackoffFunc

ExponentialBackoff returns a BackoffFunc which implements an exponential backoff using the formula: b^retries * d

type BaseRecord

type BaseRecord struct {
	Name   string
	TTL    int
	Type   string
	Value  string
	ZoneID string
}

func BaseRecordFromSchema

func BaseRecordFromSchema(s schema.BaseRecord) *BaseRecord

BaseRecordFromSchema converts a schema.BaseRecord to a BaseRecord.

func BaseRecordsFromSchema

func BaseRecordsFromSchema(s []schema.BaseRecord) []*BaseRecord

type Client

type Client struct {
	Zone   ZoneClient
	Record RecordClient
	// contains filtered or unexported fields
}

Client is a client for the Hetzner Cloud API.

func NewClient

func NewClient(options ...ClientOption) *Client

NewClient creates a new client.

func (*Client) Do

func (c *Client) Do(r *http.Request, v interface{}) (*Response, error)

Do performs an HTTP request against the API.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)

NewRequest creates an HTTP request against the API. The returned request is assigned with ctx and has all necessary headers set (auth, user agent, etc.).

type ClientOption

type ClientOption func(*Client)

A ClientOption is used to configure a Client.

func WithApplication

func WithApplication(name, version string) ClientOption

WithApplication configures a Client with the given application name and application version. The version may be blank. Programs are encouraged to at least set an application name.

func WithBackoffFunc

func WithBackoffFunc(f BackoffFunc) ClientOption

WithBackoffFunc configures a Client to use the specified backoff function.

func WithDebugWriter

func WithDebugWriter(debugWriter io.Writer) ClientOption

WithDebugWriter configures a Client to print debug information to the given writer. To, for example, print debug information on stderr, set it to os.Stderr.

func WithEndpoint

func WithEndpoint(endpoint string) ClientOption

WithEndpoint configures a Client to use the specified API endpoint.

func WithPollInterval

func WithPollInterval(pollInterval time.Duration) ClientOption

WithPollInterval configures a Client to use the specified interval when polling from the API.

func WithToken

func WithToken(token string) ClientOption

WithToken configures a Client to use the specified token for authentication.

type Error

type Error struct {
	Code    ErrorCode
	Message string
}

Error is an error returned from the API.

func ErrorFromSchema

func ErrorFromSchema(s schema.Error) Error

ErrorFromSchema converts a schema.Error to an Error.

func (Error) Error

func (e Error) Error() string

type ErrorCode

type ErrorCode int

ErrorCode represents an error code returned from the API.

const (
	ErrorCodeNotFound          ErrorCode = 404
	ErrorCodeRateLimitExceeded ErrorCode = 429
)

Error codes returned from the API.

type ListOpts

type ListOpts struct {
	Page    int // Page (starting at 1)
	PerPage int // Items per page (0 means default)
}

ListOpts specifies options for listing resources.

type Meta

type Meta struct {
	Pagination *Pagination
	Ratelimit  Ratelimit
}

Meta represents meta information included in an API response.

type Pagination

type Pagination struct {
	Page         int
	PerPage      int
	PreviousPage int
	NextPage     int
	LastPage     int
	TotalEntries int
}

Pagination represents pagination meta information.

func PaginationFromSchema

func PaginationFromSchema(s schema.MetaPagination) Pagination

PaginationFromSchema converts a schema.MetaPagination to a Pagination.

type Ratelimit

type Ratelimit struct {
	Limit     int
	Remaining int
	Reset     time.Time
}

Ratelimit represents ratelimit information.

type Record

type Record struct {
	BaseRecord
	ID       string
	Created  schema.Time
	Modified schema.Time
}

func RecordFromSchema

func RecordFromSchema(s schema.Record) *Record

RecordFromSchema converts a schema.Record to a Record.

func RecordsFromSchema

func RecordsFromSchema(s []schema.Record) []*Record

type RecordBulkCreateOpts

type RecordBulkCreateOpts struct {
	Records []RecordCreateOpts
}

RecordBulkCreateOpts specifies parameters for creating several Records at once.

type RecordBulkCreateResult

type RecordBulkCreateResult struct {
	InvalidRecords []*BaseRecord
	Records        []*Record
	ValidRecords   []*BaseRecord
}

type RecordBulkUpdateOpts

type RecordBulkUpdateOpts struct {
	Records []RecordUpdateOpts
}

RecordBulkUpdateOpts specifies parameters for creating several Records at once.

type RecordBulkUpdateResult

type RecordBulkUpdateResult struct {
	FailedRecords []*BaseRecord
	Records       []*Record
}

type RecordClient

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

func (*RecordClient) All

func (c *RecordClient) All(ctx context.Context) ([]*Record, error)

func (*RecordClient) BulkCreate

BulkCreate creates several Records at once.

func (*RecordClient) BulkUpdate

BulkUpdate updates several Records at once.

func (*RecordClient) Create

func (c *RecordClient) Create(ctx context.Context, opts RecordCreateOpts) (*Record, *Response, error)

Create creates a Record.

func (*RecordClient) Delete

func (c *RecordClient) Delete(ctx context.Context, id string) (*Response, error)

func (*RecordClient) GetByID

func (c *RecordClient) GetByID(ctx context.Context, id string) (*Record, *Response, error)

func (*RecordClient) List

func (c *RecordClient) List(ctx context.Context, opts RecordListOpts) ([]*Record, *Response, error)

List returns a list of actions for a specific page.

func (*RecordClient) Update

func (c *RecordClient) Update(ctx context.Context, id string, opts RecordUpdateOpts) (*Record, *Response, error)

Update updates a Record.

type RecordCreateOpts

type RecordCreateOpts struct {
	Name   string
	TTL    int
	Type   string
	Value  string
	ZoneID string
}

RecordCreateOpts specifies parameters for creating a Record.

type RecordListOpts

type RecordListOpts struct {
	ListOpts
	ZoneID string
}

ActionListOpts specifies options for listing actions.

type RecordUpdateOpts

type RecordUpdateOpts struct {
	Name   string
	TTL    int
	Type   string
	Value  string
	ZoneID string
}

RecordUpdateOpts specifies parameters for updating a Record.

type Response

type Response struct {
	*http.Response
	Meta Meta
}

Response represents a response from the API. It embeds http.Response.

type Zone

type Zone struct {
	ID              string
	Name            string
	TTL             int
	Created         schema.Time
	IsSecondaryDNS  bool
	LegacyDNSHost   string
	LegacyNS        []string
	Modified        schema.Time
	NS              []string
	Owner           string
	Paused          bool
	Permission      string
	Project         string
	RecordsCount    int
	Registrar       string
	Status          string
	TXTVerification ZoneTxtVerification
	Verified        schema.Time
}

func ZoneFromSchema

func ZoneFromSchema(s schema.Zone) *Zone

ZoneFromSchema converts a schema.Zone to a Zone.

type ZoneClient

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

func (*ZoneClient) All

func (c *ZoneClient) All(ctx context.Context) ([]*Zone, error)

func (*ZoneClient) Create

func (c *ZoneClient) Create(ctx context.Context, opts ZoneCreateOpts) (*Zone, *Response, error)

Create creates a Zone.

func (*ZoneClient) Delete

func (c *ZoneClient) Delete(ctx context.Context, id string) (*Response, error)

func (*ZoneClient) GetByID

func (c *ZoneClient) GetByID(ctx context.Context, id string) (*Zone, *Response, error)

func (*ZoneClient) Update

func (c *ZoneClient) Update(ctx context.Context, id string, opts ZoneUpdateOpts) (*Zone, *Response, error)

Update updates a Zone.

type ZoneCreateOpts

type ZoneCreateOpts struct {
	Name string
	TTL  int
}

ZoneCreateOpts specifies parameters for creating a Zone.

type ZoneTxtVerification

type ZoneTxtVerification struct {
	Name  string
	Token string
}

type ZoneUpdateOpts

type ZoneUpdateOpts struct {
	Name string
	TTL  int
}

ZoneUpdateOpts specifies parameters for updating a Zone.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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