apihelper

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidContentType is used when the content-type is not application/json
	ErrInvalidContentType = errors.New("Can only decode data for application/json")

	// ErrExtractingParams is used when query string params fail due to unrecognized type
	ErrExtractingParams = errors.New("Can only extract query string params from flat objects")
)

Functions

func DecodeJSON

func DecodeJSON(request *wedeploy.WeDeploy, data interface{}) error

DecodeJSON decodes a JSON response

func EncodeJSON

func EncodeJSON(data interface{}) (*bytes.Reader, error)

EncodeJSON encodes a object using its JSON annotations map and creates a reader that can be used as body for requests, for example

func ParamsFromJSON

func ParamsFromJSON(request *wedeploy.WeDeploy, data interface{})

ParamsFromJSON creates query string params from a flat object with JSON tags

func SetBody

func SetBody(request *wedeploy.WeDeploy, data interface{}) error

SetBody sets the body of a request with the JSON encoded from an object

func Validate

func Validate(request *wedeploy.WeDeploy, err error) error

Validate validates a request and sends an error on error

Types

type APIFault

type APIFault struct {
	Method  string
	URL     string
	Status  int            `json:"status"`
	Message string         `json:"message"`
	Errors  APIFaultErrors `json:"errors"`
}

APIFault is sent by the server when errors happen Method and URL MUST NOT have JSON tags

func (APIFault) Error

func (a APIFault) Error() string

func (APIFault) Get

func (a APIFault) Get(reason string) (bool, string)

Get error message for a given reason if it exists

func (APIFault) Has

func (a APIFault) Has(reason string) bool

Has checks if given error reason exists

type APIFaultError

type APIFaultError struct {
	Reason  string               `json:"reason"`
	Context APIFaultErrorContext `json:"context"`
}

APIFaultError is the error structure for the errors described by a fault

type APIFaultErrorContext

type APIFaultErrorContext map[string]interface{}

APIFaultErrorContext map

func (APIFaultErrorContext) Message

func (c APIFaultErrorContext) Message() string

Message for a given APIFaultError

type APIFaultErrors

type APIFaultErrors []APIFaultError

APIFaultErrors is the array of APIFaultError

type Client added in v1.1.5

type Client struct {
	Context config.Context // the configuration is really the user context here
}

Client for the API

func New added in v1.1.5

func New(wectx config.Context) *Client

New client

func (*Client) Auth added in v1.1.5

func (c *Client) Auth(request *wedeploy.WeDeploy)

Auth a WeDeploy request with the global authentication data

func (*Client) AuthGet added in v1.1.5

func (c *Client) AuthGet(ctx context.Context, path string, data interface{}) error

AuthGet creates an authenticated GET request for a JSON response end-point

func (*Client) URL added in v1.1.5

func (c *Client) URL(ctx context.Context, paths ...string) *wedeploy.WeDeploy

URL creates a WeDeploy URL instance

Jump to

Keyboard shortcuts

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