hdns

package
v0.0.0-...-078f61a Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package hdns is a library for the Hetzner DNS API.

Index

Constants

View Source
const Endpoint = "https://dns.hetzner.com/api/v1"

Endpoint is the base URL of the API.

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 = "1.0.0"

Version is the library's version following Semantic Versioning.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to the passed bool b.

func Int

func Int(i int) *int

Int returns a pointer to the passed integer i.

func IsError

func IsError(err error, code ErrorCode) bool

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

func String

func String(s string) *string

String returns a pointer to the passed string s.

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 Client

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

Client is a client for the Hetzner DNS 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 WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient configures a Client to perform HTTP requests with httpClient.

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 string

ErrorCode represents an error code returned from the API.

const (
	ErrorCodePaginationError     ErrorCode = "400" // Pagination selectors are mutually exclusive
	ErrorCodeUnauthorized        ErrorCode = "401" // Unathorized
	ErrorCodeForbidden           ErrorCode = "403" // Insufficient permissions
	ErrorCodeNotFound            ErrorCode = "404" // Resource not found
	ErrorCodeNotAcceptable       ErrorCode = "406" // Not acceptable
	ErrorCodeConflict            ErrorCode = "409" // Conflict
	ErrorCodeUnprocessableEntity ErrorCode = "422" // Unprocessable entity
)

Error codes returned from the API.

type Meta

type Meta struct {
	Pagination *Pagination
}

Meta represents meta information included in an API response.

type Pagination

type Pagination struct {
	Page         int
	PerPage      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 Response

type Response struct {
	*http.Response
	Meta Meta
}

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

type TxtVerification

type TxtVerification struct {
	Name  string
	Token string
}

TxtVerification represents TXT Verification of zone.

type TxtVerificationClient

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

TxtVerificationClient is a client for the TxtVerification API.

type Zone

type Zone struct {
	ID              string
	Created         time.Time
	Modified        time.Time
	LegacyDNSHost   string
	LegacyNs        []string
	Name            string
	Ns              []string
	Owner           string
	Paused          bool
	Permission      string
	Project         string
	Registrar       string
	Status          string
	TTL             uint64
	Verified        time.Time
	RecordsCount    uint64
	IsSecondaryDNS  bool
	TxtVerification TxtVerification
}

Zone represents a zone in the Hetzner DNS

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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