Documentation ¶
Overview ¶
Package rest implements Equinix REST client
Index ¶
- Constants
- type ApplicationError
- type Client
- func (c *Client) Do(method string, path string, req *resty.Request) (*resty.Response, error)
- func (c *Client) Execute(req *resty.Request, method string, path string) error
- func (c Client) GetOffsetPaginated(path string, result interface{}, conf *OffsetPaginationConfig) ([]interface{}, error)
- func (c Client) GetPaginated(path string, result interface{}, conf *PagingConfig) ([]interface{}, error)
- func (c *Client) SetPageSize(pageSize int) *Client
- type Error
- type OffsetPaginationConfig
- func (c *OffsetPaginationConfig) SetAdditionalParams(v map[string]string) *OffsetPaginationConfig
- func (c *OffsetPaginationConfig) SetDataFieldName(name string) *OffsetPaginationConfig
- func (c *OffsetPaginationConfig) SetLimitFieldName(name string) *OffsetPaginationConfig
- func (c *OffsetPaginationConfig) SetOffsetFieldName(name string) *OffsetPaginationConfig
- func (c *OffsetPaginationConfig) SetPaginationFieldName(name string) *OffsetPaginationConfig
- func (c *OffsetPaginationConfig) SetTotalFieldName(name string) *OffsetPaginationConfig
- type PagingConfig
- func (c *PagingConfig) SetAdditionalParams(v map[string]string) *PagingConfig
- func (c *PagingConfig) SetContentFieldName(v string) *PagingConfig
- func (c *PagingConfig) SetFirstPageNumber(v int) *PagingConfig
- func (c *PagingConfig) SetPageParamName(v string) *PagingConfig
- func (c *PagingConfig) SetSizeParamName(v string) *PagingConfig
- func (c *PagingConfig) SetTotalCountFieldName(v string) *PagingConfig
Constants ¶
const (
//LogLevelEnvVar is OS variable name that controlls logging level
LogLevelEnvVar = "EQUINIX_REST_LOG"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplicationError ¶
type ApplicationError struct { //Code is short error identifier Code string //Message is textual description of an error Message string //Property is a name of resource property that is related to an error Property string //AdditionalInfo provides additional information about an error AdditionalInfo string }
ApplicationError describes standardized application error
func (ApplicationError) Error ¶ added in v1.1.0
func (e ApplicationError) Error() string
type Client ¶
type Client struct { //PageSize determines default page size for GET requests on resource collections PageSize int *resty.Client // contains filtered or unexported fields }
Client describes Equinix REST client implementation. Implementation is based on github.com/go-resty
func NewClient ¶
NewClient creates new Equinix REST client with a given HTTP context, URL and http client. Equinix REST client is based on github.com/go-resty
func (*Client) Do ¶ added in v1.3.0
Do runs given method on a given path with given request and returns response and error
func (Client) GetOffsetPaginated ¶ added in v1.3.0
func (c Client) GetOffsetPaginated(path string, result interface{}, conf *OffsetPaginationConfig) ([]interface{}, error)
GetOffsetPaginated uses HTTP GET requests to retrieve list of all objects from paginated responses that use offset & limit attributes in a separate pagination object. Requests are executed against given path, pagination aspects are controlled with PagingConfig
func (Client) GetPaginated ¶
func (c Client) GetPaginated(path string, result interface{}, conf *PagingConfig) ([]interface{}, error)
GetPaginated uses HTTP GET requests to retrieve list of all objects from paginated responses. Requests are executed against given path, pagination aspects are controlled with PagingConfig
func (*Client) SetPageSize ¶
SetPageSize sets page size used by Equinix REST client for paginated queries
type Error ¶
type Error struct { //HTTPCode is HTTP status code HTTPCode int //Message is textual, general description of an error Message string //ApplicationErrors is list of one or more application sub-errors ApplicationErrors []ApplicationError }
Error describes REST API error
type OffsetPaginationConfig ¶ added in v1.3.0
type OffsetPaginationConfig struct { PaginationFieldName string OffsetFieldName string LimitFieldName string TotalFieldName string DataFieldName string AdditionalParams map[string]string }
OffsetPaginationConfig is used to describe pagination aspects
func DefaultOffsetPagingConfig ¶ added in v1.3.0
func DefaultOffsetPagingConfig() *OffsetPaginationConfig
DefaultOffsetPagingConfig returns OffsetPaginationConfig with default values
func (*OffsetPaginationConfig) SetAdditionalParams ¶ added in v1.3.0
func (c *OffsetPaginationConfig) SetAdditionalParams(v map[string]string) *OffsetPaginationConfig
SetAdditionalParams sets additional query parameters that will be used in a request
func (*OffsetPaginationConfig) SetDataFieldName ¶ added in v1.3.0
func (c *OffsetPaginationConfig) SetDataFieldName(name string) *OffsetPaginationConfig
SetDataFieldName sets data field name
func (*OffsetPaginationConfig) SetLimitFieldName ¶ added in v1.3.0
func (c *OffsetPaginationConfig) SetLimitFieldName(name string) *OffsetPaginationConfig
SetLimitFieldName sets limit field name
func (*OffsetPaginationConfig) SetOffsetFieldName ¶ added in v1.3.0
func (c *OffsetPaginationConfig) SetOffsetFieldName(name string) *OffsetPaginationConfig
SetOffsetFieldName sets offset field name
func (*OffsetPaginationConfig) SetPaginationFieldName ¶ added in v1.3.0
func (c *OffsetPaginationConfig) SetPaginationFieldName(name string) *OffsetPaginationConfig
SetPaginationFieldName sets pagination field name
func (*OffsetPaginationConfig) SetTotalFieldName ¶ added in v1.3.0
func (c *OffsetPaginationConfig) SetTotalFieldName(name string) *OffsetPaginationConfig
SetTotalFieldName sets total field name
type PagingConfig ¶
type PagingConfig struct { //TotalCountFieldName is name of a field in a response struct that indicates total number of elements in collection TotalCountFieldName string //ContentFieldName is a name of a field that holds slice of elements ContentFieldName string //SizeParamName is a name of page size query parameter SizeParamName string //PageParamName is a name of page number query parameter PageParamName string //FirstPageNumber is a first page number returned by the server (typically 0 or 1) FirstPageNumber int //AdditionalParams is a map of additional query parameters that will be set in GET request AdditionalParams map[string]string }
PagingConfig is used to describe pagination aspects like naming of query parameters
func DefaultPagingConfig ¶
func DefaultPagingConfig() *PagingConfig
DefaultPagingConfig returns PagingConfig with default values
func (*PagingConfig) SetAdditionalParams ¶
func (c *PagingConfig) SetAdditionalParams(v map[string]string) *PagingConfig
SetAdditionalParams sets additional query parameters that will be used in a request
func (*PagingConfig) SetContentFieldName ¶
func (c *PagingConfig) SetContentFieldName(v string) *PagingConfig
SetContentFieldName sets totalCount field name
func (*PagingConfig) SetFirstPageNumber ¶
func (c *PagingConfig) SetFirstPageNumber(v int) *PagingConfig
SetFirstPageNumber sets number of a fist page as returned by the server
func (*PagingConfig) SetPageParamName ¶
func (c *PagingConfig) SetPageParamName(v string) *PagingConfig
SetPageParamName sets page query parameter name
func (*PagingConfig) SetSizeParamName ¶
func (c *PagingConfig) SetSizeParamName(v string) *PagingConfig
SetSizeParamName sets size query parameter name
func (*PagingConfig) SetTotalCountFieldName ¶
func (c *PagingConfig) SetTotalCountFieldName(v string) *PagingConfig
SetTotalCountFieldName sets totalCount field name