rest

package
v0.0.0-...-dfd3d55 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2015 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOptions

func AddOptions(s string, opt interface{}) (string, error)

AddOptions adds the parameters in opt as URL query parameters to s. opt must be a struct whose fields may contain "url" tags.

func BasicAuth

func BasicAuth(username, password string) string

BasicAuth takes a username and password string and returns a base64-encoded string

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.

func RegisterDecoder

func RegisterDecoder(format string, fn DecoderFunc)

func RegisterEncoder

func RegisterEncoder(format string, fn EncoderFunc)

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	Endpoint   *url.URL
	Header     http.Header
	Query      url.Values

	EncoderFunc EncoderFunc
	DecoderFunc DecoderFunc
}

Client type

func New

func New(endpoint string, client *http.Client) (*Client, error)

New returns a Client with a configured endpoint and http.Client

func NewFromURL

func NewFromURL(endpoint *url.URL, client *http.Client) *Client

NewFromURL returns a Client with a configured endpoint from a url.URL and http.Client

func (*Client) Decode

func (c *Client) Decode(v interface{}, r io.Reader) error

func (*Client) Decoder

func (c *Client) Decoder(r io.Reader) (Decoder, error)

func (*Client) Delete

func (c *Client) Delete(path string, input, output interface{}) (*http.Response, error)

Delete makes a DELETE request

func (*Client) Do

func (c *Client) Do(req *http.Request, output interface{}) (*http.Response, error)

Do performs the request.

func (*Client) Encode

func (c *Client) Encode(v interface{}, w io.Writer) error

func (*Client) Encoder

func (c *Client) Encoder(w io.Writer) (Encoder, error)

func (*Client) Get

func (c *Client) Get(path string, output interface{}) (*http.Response, error)

func (*Client) NewRequest

func (c *Client) NewRequest(meth string, path string, input interface{}) (*http.Request, error)

NewRequest returns a new http.Request object

func (*Client) Post

func (c *Client) Post(path string, input, output interface{}) (*http.Response, error)

Post makes a POST request

func (*Client) Put

func (c *Client) Put(path string, input, output interface{}) (*http.Response, error)

Put makes a PUT request

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

type DecoderFunc

type DecoderFunc func(r io.Reader) Decoder

type Encoder

type Encoder interface {
	Encode(v interface{}) error
}

type EncoderFunc

type EncoderFunc func(w io.Writer) Encoder

type HTTPError

type HTTPError struct {
	Response *http.Response
}

HTTPError represents an API error.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Jump to

Keyboard shortcuts

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