api

package
v0.0.0-...-036eace Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "1.0"

Version of the builtin API

Variables

This section is empty.

Functions

func Path

func Path(path ...string) string

Path prefixes API version to a path

Types

type Operation

type Operation struct {
	ID          string                 `json:"id" yaml:"id"`
	Description string                 `json:"description" yaml:"description"`
	CreatedAt   time.Time              `json:"created_at" yaml:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at" yaml:"updated_at"`
	Status      string                 `json:"status" yaml:"status"`
	StatusCode  StatusCode             `json:"status_code" yaml:"status_code"`
	Resources   map[string][]string    `json:"resources" yaml:"resources"`
	Metadata    map[string]interface{} `json:"metadata" yaml:"metadata"`
	Err         string                 `json:"err" yaml:"err"`
}

Operation represents a background operation as result of a REST POST, PATCH, DELETE or PUT

type Response

type Response struct {
	Type ResponseType `json:"type" yaml:"type"`

	// Valid only for Sync responses
	Status     string `json:"status" yaml:"status"`
	StatusCode int    `json:"status_code" yaml:"status_code"`

	// Valid only for Async responses
	Operation string `json:"operation" yaml:"operation"`

	// Valid only for Error responses
	Code  int    `json:"error_code" yaml:"error_code"`
	Error string `json:"error" yaml:"error"`

	// Valid for Sync and Error responses
	Metadata json.RawMessage `json:"metadata" yaml:"metadata"`
}

Response represents a LXD operation

func (*Response) MetadataAsMap

func (r *Response) MetadataAsMap() (map[string]interface{}, error)

MetadataAsMap parses the Response metadata into a map

func (*Response) MetadataAsOperation

func (r *Response) MetadataAsOperation() (*Operation, error)

MetadataAsOperation turns the Response metadata into an Operation

func (*Response) MetadataAsStringSlice

func (r *Response) MetadataAsStringSlice() ([]string, error)

MetadataAsStringSlice parses the Response metadata into a slice of string

func (*Response) MetadataAsStruct

func (r *Response) MetadataAsStruct(target interface{}) error

MetadataAsStruct parses the Response metadata into a provided struct

type ResponseRaw

type ResponseRaw struct {
	Response `yaml:",inline"`
	Metadata interface{} `json:"metadata" yaml:"metadata"`
}

ResponseRaw represents a REST operation in its original form

type ResponseType

type ResponseType string

ResponseType represents a valid LXD response type

const (
	ResponseTypeSync  ResponseType = "sync"
	ResponseTypeAsync ResponseType = "async"
	ResponseTypeError ResponseType = "error"
)

"there are three standard return types: Standard return value, Background operation, Error", each returning a JSON object with the following "type" field:

type StatusCode

type StatusCode int

StatusCode represents a valid REST operation status code

const (
	Created    StatusCode = 100
	Started    StatusCode = 101
	Stopped    StatusCode = 102
	Running    StatusCode = 103
	Cancelling StatusCode = 104
	Pending    StatusCode = 105
	Starting   StatusCode = 106
	Stopping   StatusCode = 107
	Aborting   StatusCode = 108
	Freezing   StatusCode = 109
	Frozen     StatusCode = 110
	Thawed     StatusCode = 111
	Error      StatusCode = 112

	Success StatusCode = 200

	Failure   StatusCode = 400
	Cancelled StatusCode = 401
)

status codes

func (StatusCode) IsFinal

func (o StatusCode) IsFinal() bool

IsFinal will return true if the status code indicates an end state

func (StatusCode) String

func (o StatusCode) String() string

String returns a suitable string representation for the status code

Jump to

Keyboard shortcuts

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