client

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package client contains a generic JSON API client for cockpit, cloud and jarvis

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("resource not found (HTTP 404)")

ErrNotFound error for HTTP 404 responses

Functions

This section is empty.

Types

type Client

type Client struct {
	Endpoint     string // Endpoint URL
	Language     string // You can specify a locale (en|de)
	Retries      int    // using exponential backoff
	*http.Client        // http client used for doing the requests
}

Client implements a generic client for cockpit, cloud and jarvis

func New

func New(endpoint string) *Client

New creates a new Client with configured endpoint and the default http client

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do executes a request and returns its response while logging and tracing it

func (*Client) DoJSON

func (c *Client) DoJSON(ctx context.Context, req *http.Request, v interface{}) error

DoJSON executes a request and decodes its response it into the given value v

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, url fmt.Stringer, v interface{}) error

GetJSON gets the json from the passed url and decodes its response into the given value v

func (*Client) URL

func (c *Client) URL(path string, values url.Values) (*url.URL, error)

URL generates a new URL for the given path and url values

type ErrRequest

type ErrRequest struct {
	ErrorDetail struct {
		Type  string `json:"type"`
		Codes []struct {
			Param  string `json:"param"`
			CodeID string `json:"code_id"`
		} `json:"codes"`
	} `json:"error"`
}

ErrRequest contains error details

func (*ErrRequest) Error

func (e *ErrRequest) Error() string

Error implements the error interface

type UnixTime

type UnixTime time.Time

UnixTime for json int values that represent a unix timestamp

func (UnixTime) MarshalJSON

func (r UnixTime) MarshalJSON() ([]byte, error)

MarshalJSON is generated so TripStatus satisfies json.Marshaler.

func (*UnixTime) UnmarshalJSON

func (r *UnixTime) UnmarshalJSON(data []byte) error

UnmarshalJSON is generated so TripStatus satisfies json.Unmarshaler.

Jump to

Keyboard shortcuts

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