linode

package module
v0.0.0-...-37e8452 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2016 License: BSD-2-Clause Imports: 7 Imported by: 0

README

linode

linode is a library for interacting with the Linode API.

Support for the API is as follows:

  • DNS: Supported.
  • Raw interaction with the API: Supported.
  • Batch requests: Partially supported.

Usage

This section definitely needs to be fleshed out more in the future, but until that point, here is a simple example:

import (
        "log"

        "github.com/timewasted/linode/dns"
)

linode := dns.New("<insert api key here>")
domain, err := linode.GetDomain("example.com")
if err != nil {
        log.Fatalln(err)
}
resource, err := linode.CreateDomainResourceTXT(domain.DomainID, "_acme-challenge", "super secret value", 60)
if err != nil {
        log.Fatalln(err)
}
// Do stuff with resource

Documentation

Index

Constants

View Source
const (
	ERR_OK                        = 0
	ERR_BAD_REQUEST               = 1
	ERR_NO_ACTION_REQUESTED       = 2
	ERR_CLASS_DOES_NOT_EXIST      = 3
	ERR_AUTHENTICATION_FAILED     = 4
	ERR_OBJECT_NOT_FOUND          = 5
	ERR_REQUIRED_PROPERTY_MISSING = 6
	ERR_INVALID_PROPERTY          = 7
	ERR_DATA_VALIDATION_FAILED    = 8
	ERR_METHOD_NOT_IMPLEMENTED    = 9
	ERR_TOO_MANY_BATCHED_REQUESTS = 10
	ERR_REQUEST_INVALID_JSON      = 11
	ERR_BATCH_TIMED_OUT           = 12
	ERR_PERMISSION_DENIED         = 13
	ERR_API_RATE_LIMIT_EXCEEDED   = 14

	ERR_CREDIT_CARD_CHARGE_FAILED = 30
	ERR_CREDIT_CARD_EXPIRED       = 31

	ERR_LINODES_PER_HOUR_LIMIT_EXCEEDED = 40
	ERR_LINODE_STILL_HAS_DISKS          = 41
)
View Source
const (
	// ApiEndpoint is the base URL for the Linode API endpoint.
	ApiEndpoint = "https://api.linode.com/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

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

Action represents an action to be performed.

type Error

type Error struct {
	Err error
	// contains filtered or unexported fields
}

Error represents an error, either API related or not.

func NewApiError

func NewApiError(code int, msg string) *Error

NewApiError returns an instance of Error which represents an API error.

func NewError

func NewError(err error) *Error

NewError returns an instance of Error which represents a non-API error.

func (*Error) Error

func (e *Error) Error() string

Error implements the Error() method of the error interface.

func (*Error) IsApiError

func (e *Error) IsApiError() bool

IsApiError returns true if the error is an API error, or false otherwise.

type Linode

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

Linode represents the interface to the Linode API.

func New

func New(apiKey string) *Linode

New returns a pointer to a new Linode object.

func (*Linode) Batch

func (l *Linode) Batch(action string, params Parameters, result interface{})

Batch adds a new action to the batch request to be performed.

func (*Linode) Process

func (l *Linode) Process() ([]*Response, error)

Process performs all batch actions that have been added.

func (*Linode) Request

func (l *Linode) Request(action string, params Parameters, result interface{}) (*Response, error)

Request performs a single API operation and returns the full response.

func (*Linode) Reset

func (l *Linode) Reset()

Reset clears the list of actions to be performed.

func (*Linode) SetEndpoint

func (l *Linode) SetEndpoint(endpoint string)

SetEndpoint sets the endpoint that all API requests will be sent to. This should only be used for testing/debugging purposes!

type Parameters

type Parameters map[string]string

Parameters represents the parameters that are passed for an API call.

func (Parameters) Del

func (p Parameters) Del(key string)

Del deletes the parameter associated with key.

func (Parameters) Encode

func (p Parameters) Encode() string

Encode encodes the parameters into "URL encoded" form ("bar=baz&foo=quux") sorted by key.

func (Parameters) Get

func (p Parameters) Get(key string) string

Get gets the parameter associated with the given key. If no parameter is associated with the key, Get returns the empty string.

func (Parameters) Set

func (p Parameters) Set(key, value string)

Set sets the key to value. It replaces any existing value.

type Response

type Response struct {
	Action  string          `json:"ACTION"`
	RawData json.RawMessage `json:"DATA"`
	Errors  []ResponseError `json:"ERRORARRAY"`
	Data    interface{}     `json:"-"`
}

Response represents the response to an API call. Data is defined as an interface, because each API call will return a different response. It is the user's responsibility to turn it into something useful.

type ResponseError

type ResponseError struct {
	Code    int    `json:"ERRORCODE"`
	Message string `json:"ERRORMESSAGE"`
}

ResponseError represents an error returned by an API call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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