Version: v0.7.1 Latest Latest

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

Go to latest
Published: Aug 18, 2017 License: MIT Imports: 14 Imported by: 12




This section is empty.


This section is empty.


func ValidateAPIVersion

func ValidateAPIVersion(v string) error

ValidateAPIVersion checks if the given API version is valid.

func ValidateURL

func ValidateURL(u string) error

ValidateURL validates if the given URL is valid for the SensorBee API server.


type Method

type Method int

Method has a type of HTTP methods.

const (
	// Get represents GET method.
	Get Method = iota

	// Post represents POST method.

	// Put represents PUT method.

	// Delete represents DELETE method.

func (Method) String

func (r Method) String() string

type Requester

type Requester struct {
	// contains filtered or unexported fields

Requester sends raw HTTP requests to the server. Requester doesn't have a state, so it can be used concurrently.

func NewRequester

func NewRequester(url, version string) (*Requester, error)

NewRequester creates a new requester

func NewRequesterWithClient

func NewRequesterWithClient(url, version string, cli *http.Client) (*Requester, error)

NewRequesterWithClient creates a new requester with a custom HTTP client.

func (*Requester) Do

func (r *Requester) Do(method Method, path string, body interface{}) (*Response, error)

Do sends a JSON request to server. The caller has to close the body of the response.

func (*Requester) DoWithRequest

func (r *Requester) DoWithRequest(req *http.Request) (*Response, error)

DoWithRequest sends a custom HTTP request to server.

func (*Requester) NewRequest

func (r *Requester) NewRequest(method Method, apiPath string, bodyJSON interface{}) (*http.Request, error)

NewRequest creates a new HTTP request having a JSON content. The caller has to close the body of the response.

type Response

type Response struct {
	// Raw has a raw HTTP response.
	Raw *http.Response
	// contains filtered or unexported fields

Response wraps a raw HTTP response. Response must only be manipulated from one goroutine (i.e. it isn't thread-safe).

func (*Response) Body

func (r *Response) Body() ([]byte, error)

Body returns the response body. Invoking this method will close Raw.Body. Don't call this method on a stream response (i.e. a response having unlimited length).

func (*Response) Close

func (r *Response) Close() error

Close closes the body of the response.

func (*Response) Error

func (r *Response) Error() (*response.Error, error)

Error reads an error response from the server. It fails if the response isn't an error.

func (*Response) IsError

func (r *Response) IsError() bool

IsError returns true when the response is an error.

func (*Response) IsStream

func (r *Response) IsStream() bool

IsStream returns true when the response from the server is a stream which might have unbounded data.

func (*Response) ReadJSON

func (r *Response) ReadJSON(js interface{}) error

ReadJSON reads the response body as a json and unmarshals it to the given data structure. This method closed the response body. This method can be called multiple times with different types of arguments. Don't call this method on a stream response (i.e. a response having unlimited length).

func (*Response) ReadStreamJSON

func (r *Response) ReadStreamJSON() (<-chan interface{}, error)

ReadStreamJSON returns multiple parsed JSONs as interface{}. The caller must call Response.Close when it require no more JSONs.

func (*Response) StreamError

func (r *Response) StreamError() error

StreamError returns an error which occurred in a goroutine spawned from ReadStreamJSON method. Don't call this method before the channel returned from ReadStreamJSON is closed.

Jump to

Keyboard shortcuts

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