Documentation ¶
Index ¶
- func APIResponseJSONDeserializer(r *APIResponse, out interface{}) error
- func DeleteRaw(conn Connection, resource string, body interface{}, responseBody interface{}, ...) error
- func GetRaw(conn Connection, resource string, parameters APIRequestParameters, ...) error
- func InvokeRequestAll[T any](getFunc PaginatedGetFunc[T], parameters APIRequestParameters) ([]T, error)
- func PatchRaw(conn Connection, resource string, body interface{}, responseBody interface{}, ...) error
- func PostRaw(conn Connection, resource string, body interface{}, responseBody interface{}, ...) error
- func PutRaw(conn Connection, resource string, body interface{}, responseBody interface{}, ...) error
- type APIConnection
- func (c *APIConnection) Delete(resource string, body interface{}) (*APIResponse, error)
- func (c *APIConnection) Get(resource string, parameters APIRequestParameters) (*APIResponse, error)
- func (c *APIConnection) Invoke(request APIRequest) (*APIResponse, error)
- func (c *APIConnection) InvokeRequest(req *http.Request) (*APIResponse, error)
- func (c *APIConnection) NewRequest(request APIRequest) (*http.Request, error)
- func (c *APIConnection) Patch(resource string, body interface{}) (*APIResponse, error)
- func (c *APIConnection) Post(resource string, body interface{}) (*APIResponse, error)
- func (c *APIConnection) Put(resource string, body interface{}) (*APIResponse, error)
- type APIKeyCredentials
- type APIRequest
- type APIRequestBodyDefaultValidator
- type APIRequestFiltering
- type APIRequestFilteringOperator
- type APIRequestPagination
- type APIRequestParameters
- func (p *APIRequestParameters) Copy() APIRequestParameters
- func (p *APIRequestParameters) WithFilter(filters ...APIRequestFiltering) *APIRequestParameters
- func (p *APIRequestParameters) WithPagination(pagination APIRequestPagination) *APIRequestParameters
- func (p *APIRequestParameters) WithSorting(sorting APIRequestSorting) *APIRequestParameters
- type APIRequestSorting
- type APIResponse
- type APIResponseBody
- type APIResponseBodyData
- func Delete[T any](conn Connection, resource string, body interface{}, ...) (*APIResponseBodyData[T], error)
- func Get[T any](conn Connection, resource string, parameters APIRequestParameters, ...) (*APIResponseBodyData[T], error)
- func Patch[T any](conn Connection, resource string, body interface{}, ...) (*APIResponseBodyData[T], error)
- func Post[T any](conn Connection, resource string, body interface{}, ...) (*APIResponseBodyData[T], error)
- func Put[T any](conn Connection, resource string, body interface{}, ...) (*APIResponseBodyData[T], error)
- type APIResponseBodyError
- type APIResponseBodyErrorItem
- type APIResponseBodyStringData
- type APIResponseMetadata
- type APIResponseMetadataPagination
- type APIResponseMetadataPaginationLinks
- type AuthHeaders
- type Connection
- type Credentials
- type Date
- type DateTime
- type Enum
- type EnumSlice
- type ErrInvalidEnumValue
- type IPAddress
- type Paginated
- func (p *Paginated[T]) CurrentPage() int
- func (p *Paginated[T]) First() (*Paginated[T], error)
- func (p *Paginated[T]) Items() []T
- func (p *Paginated[T]) Last() (*Paginated[T], error)
- func (p *Paginated[T]) Next() (*Paginated[T], error)
- func (p *Paginated[T]) Previous() (*Paginated[T], error)
- func (p *Paginated[T]) Total() int
- func (p *Paginated[T]) TotalPages() int
- type PaginatedGetFunc
- type RequestSerializer
- type ResponseDeserializer
- type ResponseHandler
- type Validatable
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIResponseJSONDeserializer ¶ added in v1.14.4
func APIResponseJSONDeserializer(r *APIResponse, out interface{}) error
func DeleteRaw ¶ added in v1.13.0
func DeleteRaw(conn Connection, resource string, body interface{}, responseBody interface{}, handlers ...ResponseHandler) error
func GetRaw ¶ added in v1.13.0
func GetRaw(conn Connection, resource string, parameters APIRequestParameters, responseBody interface{}, handlers ...ResponseHandler) error
func InvokeRequestAll ¶
func InvokeRequestAll[T any](getFunc PaginatedGetFunc[T], parameters APIRequestParameters) ([]T, error)
InvokeRequestAll is a convenience method for initialising RequestAll and calling Invoke()
func PatchRaw ¶ added in v1.13.0
func PatchRaw(conn Connection, resource string, body interface{}, responseBody interface{}, handlers ...ResponseHandler) error
func PostRaw ¶ added in v1.13.0
func PostRaw(conn Connection, resource string, body interface{}, responseBody interface{}, handlers ...ResponseHandler) error
func PutRaw ¶ added in v1.13.0
func PutRaw(conn Connection, resource string, body interface{}, responseBody interface{}, handlers ...ResponseHandler) error
Types ¶
type APIConnection ¶
type APIConnection struct { HTTPClient *http.Client Credentials Credentials APIURI string APIScheme string Headers http.Header UserAgent string }
func NewAPIConnection ¶
func NewAPIConnection(credentials Credentials) *APIConnection
func NewAPIKeyCredentialsAPIConnection ¶
func NewAPIKeyCredentialsAPIConnection(apiKey string) *APIConnection
NewAPIKeyCredentialsAPIConnection creates a new client
func (*APIConnection) Delete ¶
func (c *APIConnection) Delete(resource string, body interface{}) (*APIResponse, error)
Delete invokes a DELETE request, returning an APIResponse
func (*APIConnection) Get ¶
func (c *APIConnection) Get(resource string, parameters APIRequestParameters) (*APIResponse, error)
Get invokes a GET request, returning an APIResponse
func (*APIConnection) Invoke ¶
func (c *APIConnection) Invoke(request APIRequest) (*APIResponse, error)
Invoke invokes a request, returning an APIResponse
func (*APIConnection) InvokeRequest ¶
func (c *APIConnection) InvokeRequest(req *http.Request) (*APIResponse, error)
InvokeRequest invokes a request, returning an APIResponse
func (*APIConnection) NewRequest ¶
func (c *APIConnection) NewRequest(request APIRequest) (*http.Request, error)
NewRequest generates a new Request from given parameters
func (*APIConnection) Patch ¶
func (c *APIConnection) Patch(resource string, body interface{}) (*APIResponse, error)
Patch invokes a PATCH request, returning an APIResponse
func (*APIConnection) Post ¶
func (c *APIConnection) Post(resource string, body interface{}) (*APIResponse, error)
Post invokes a POST request, returning an APIResponse
func (*APIConnection) Put ¶
func (c *APIConnection) Put(resource string, body interface{}) (*APIResponse, error)
Put invokes a PUT request, returning an APIResponse
type APIKeyCredentials ¶
type APIKeyCredentials struct {
APIKey string
}
func (*APIKeyCredentials) GetAuthHeaders ¶
func (c *APIKeyCredentials) GetAuthHeaders() AuthHeaders
GetAuthHeaders returns the Authorization header for API key
type APIRequest ¶
type APIRequest struct { Method string Resource string Body interface{} Parameters APIRequestParameters }
type APIRequestBodyDefaultValidator ¶
type APIRequestBodyDefaultValidator struct { }
APIRequestBodyDefaultValidator provides convenience method Validate() for validating a struct/item, utilising the validator.v9 package
func (*APIRequestBodyDefaultValidator) Validate ¶
func (a *APIRequestBodyDefaultValidator) Validate(v interface{}) *ValidationError
Validate performs validation on item v using the validator.v9 package
type APIRequestFiltering ¶
type APIRequestFiltering struct { Property string Operator APIRequestFilteringOperator Value []string }
func NewAPIRequestFiltering ¶
func NewAPIRequestFiltering(property string, operator APIRequestFilteringOperator, value []string) *APIRequestFiltering
type APIRequestFilteringOperator ¶
type APIRequestFilteringOperator int
const ( // EQOperator - equals EQOperator APIRequestFilteringOperator = iota // LKOperator - like LKOperator // GTOperator - greater than GTOperator // LTOperator - less than LTOperator // INOperator - in set INOperator // NEQOperator - not equal NEQOperator // NINOperator - not in set NINOperator // NLKOperator - not like NLKOperator )
func ParseOperator ¶
func ParseOperator(o string) (APIRequestFilteringOperator, error)
ParseOperator attempts to parse an operator from string
func (APIRequestFilteringOperator) String ¶
func (o APIRequestFilteringOperator) String() string
type APIRequestPagination ¶
type APIRequestParameters ¶
type APIRequestParameters struct { Pagination APIRequestPagination Sorting APIRequestSorting Filtering []APIRequestFiltering }
APIRequestParameters holds a collection of supported API request parameters
func NewAPIRequestParameters ¶
func NewAPIRequestParameters() *APIRequestParameters
func (*APIRequestParameters) Copy ¶
func (p *APIRequestParameters) Copy() APIRequestParameters
func (*APIRequestParameters) WithFilter ¶
func (p *APIRequestParameters) WithFilter(filters ...APIRequestFiltering) *APIRequestParameters
WithFilter is a fluent method for adding a set of filters to request parameters
func (*APIRequestParameters) WithPagination ¶
func (p *APIRequestParameters) WithPagination(pagination APIRequestPagination) *APIRequestParameters
WithPagination is a fluent method for adding pagination to request parameters
func (*APIRequestParameters) WithSorting ¶
func (p *APIRequestParameters) WithSorting(sorting APIRequestSorting) *APIRequestParameters
WithSorting is a fluent method for adding sorting to request parameters
type APIRequestSorting ¶
type APIResponse ¶
APIResponse represents the base API response
func (*APIResponse) HandleResponse ¶
func (r *APIResponse) HandleResponse(respBody interface{}, handlers ...ResponseHandler) error
HandleResponse deserializes the response body into provided respBody, and validates the response using the optionally provided ResponseHandler handler
func (*APIResponse) ValidateStatusCode ¶
func (r *APIResponse) ValidateStatusCode(codes ...int) bool
ValidateStatusCode validates the API response
type APIResponseBody ¶
type APIResponseBody struct { APIResponseBodyError Metadata APIResponseMetadata `json:"meta"` }
APIResponseBody represents the base API response body
type APIResponseBodyData ¶
type APIResponseBodyData[T any] struct { APIResponseBody Data T `json:"data"` }
APIResponseBodyStringData represents the API response body containing generic data
func Delete ¶ added in v1.10.0
func Delete[T any](conn Connection, resource string, body interface{}, handlers ...ResponseHandler) (*APIResponseBodyData[T], error)
func Get ¶ added in v1.10.0
func Get[T any](conn Connection, resource string, parameters APIRequestParameters, handlers ...ResponseHandler) (*APIResponseBodyData[T], error)
func Patch ¶ added in v1.10.0
func Patch[T any](conn Connection, resource string, body interface{}, handlers ...ResponseHandler) (*APIResponseBodyData[T], error)
func Post ¶ added in v1.10.0
func Post[T any](conn Connection, resource string, body interface{}, handlers ...ResponseHandler) (*APIResponseBodyData[T], error)
func Put ¶ added in v1.10.0
func Put[T any](conn Connection, resource string, body interface{}, handlers ...ResponseHandler) (*APIResponseBodyData[T], error)
type APIResponseBodyError ¶ added in v1.10.1
type APIResponseBodyError struct { Errors []APIResponseBodyErrorItem `json:"errors"` Message string `json:"message"` }
func (*APIResponseBodyError) Error ¶ added in v1.10.1
func (e *APIResponseBodyError) Error() string
type APIResponseBodyErrorItem ¶ added in v1.10.1
type APIResponseBodyErrorItem struct { Title string `json:"title"` Detail string `json:"detail"` Status int `json:"status"` Source string `json:"source"` }
APIResponseBodyErrorItem represents an API response error
func (*APIResponseBodyErrorItem) Error ¶ added in v1.10.1
func (a *APIResponseBodyErrorItem) Error() string
type APIResponseBodyStringData ¶
type APIResponseBodyStringData struct { APIResponseBody Data string `json:"data"` }
APIResponseBodyStringData represents the API response body containing string data
type APIResponseMetadata ¶
type APIResponseMetadata struct {
Pagination APIResponseMetadataPagination `json:"pagination"`
}
APIResponseMetadata represents the API response metadata
type APIResponseMetadataPagination ¶
type APIResponseMetadataPagination struct { Total int `json:"total"` Count int `json:"count"` PerPage int `json:"per_page"` TotalPages int `json:"total_pages"` Links APIResponseMetadataPaginationLinks `json:"links"` }
APIResponseMetadataPagination represents the API response pagination data
type APIResponseMetadataPaginationLinks ¶
type APIResponseMetadataPaginationLinks struct { Next string `json:"next"` Previous string `json:"previous"` First string `json:"first"` Last string `json:"last"` }
APIResponseMetadataPaginationLinks represents the links returned within the API response pagination data
type AuthHeaders ¶
AuthHeaders is a string map of authorization headers
type Connection ¶
type Connection interface { Get(resource string, parameters APIRequestParameters) (*APIResponse, error) Post(resource string, body interface{}) (*APIResponse, error) Put(resource string, body interface{}) (*APIResponse, error) Patch(resource string, body interface{}) (*APIResponse, error) Delete(resource string, body interface{}) (*APIResponse, error) Invoke(request APIRequest) (*APIResponse, error) }
type Credentials ¶
type Credentials interface {
GetAuthHeaders() AuthHeaders
}
type EnumSlice ¶
type EnumSlice []Enum
func (EnumSlice) String ¶
String returns string containing a comma separated list of enum string values
func (EnumSlice) StringSlice ¶
StringSlice returns a slice of strings containing the string values of enums for EnumSlice
type ErrInvalidEnumValue ¶
type ErrInvalidEnumValue struct {
Message string
}
func NewErrInvalidEnumValue ¶
func NewErrInvalidEnumValue(msg string) *ErrInvalidEnumValue
func (*ErrInvalidEnumValue) Error ¶
func (e *ErrInvalidEnumValue) Error() string
type Paginated ¶
type Paginated[T any] struct { // contains filtered or unexported fields }
func NewPaginated ¶
func NewPaginated[T any](body *APIResponseBodyData[[]T], parameters APIRequestParameters, getFunc PaginatedGetFunc[T]) *Paginated[T]
NewPaginated returns a pointer to an initialised Paginated
func (*Paginated[T]) CurrentPage ¶
CurrentPage returns the current page
func (*Paginated[T]) Items ¶
func (p *Paginated[T]) Items() []T
TotalPages returns the total number of pages
func (*Paginated[T]) Previous ¶
Previous returns the the previous page, or nil if current page is the first page
func (*Paginated[T]) TotalPages ¶
TotalPages returns the total number of pages
type PaginatedGetFunc ¶
type PaginatedGetFunc[T any] func(parameters APIRequestParameters) (*Paginated[T], error)
PaginatedGetFunc represents a function which can be called for returning an implementation of Paginated
type RequestSerializer ¶ added in v1.14.4
type ResponseDeserializer ¶ added in v1.13.0
type ResponseDeserializer interface {
Deserialize(r *APIResponse) error
}
type ResponseHandler ¶
type ResponseHandler func(resp *APIResponse) error
func NotFoundResponseHandler ¶ added in v1.10.0
func NotFoundResponseHandler(err error) ResponseHandler
func StatusCodeResponseHandler ¶ added in v1.10.0
func StatusCodeResponseHandler(code int, err error) ResponseHandler
type Validatable ¶
type Validatable interface {
Validate() *ValidationError
}
type ValidationError ¶
type ValidationError struct {
Message string
}
func NewValidationError ¶
func NewValidationError(msg string) *ValidationError
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string