client

package
v0.0.0-...-ffdcb7f Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents interactions with a API server

func New

func New(url string, options ...Option) (*Client, error)

New lets you connect to a remote daemon over HTTP.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the http client used for the connection. This can be used to set custom http options.

func (*Client) Query

func (c *Client) Query(
	method, path string,
	data interface{},
	eTag string,
) (*Response, string, error)

Query allows directly querying the API

func (*Client) Websocket

func (c *Client) Websocket(path string) (*websocket.Conn, error)

Websocket allows directly connection to API websockets

type Option

type Option func(*options)

Option to be passed to Connect to customize the resulting instance.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the httpClient on the option

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger on the option

func WithProxy

func WithProxy(proxy func(*http.Request) (*url.URL, error)) Option

WithProxy sets the proxy on the option

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent sets the userAgent on the option

type Response

type Response struct {
	Type ResponseType `json:"type" yaml:"type"`

	// Valid only for Sync responses
	Status     string `json:"status" yaml:"status"`
	StatusCode int    `json:"status_code" yaml:"status_code"`

	// Valid only for Async responses
	Operation string `json:"operation" yaml:"operation"`

	// Valid only for Error responses
	Code  int    `json:"error_code" yaml:"error_code"`
	Error string `json:"error" yaml:"error"`

	// Valid for Sync and Error responses
	Metadata json.RawMessage `json:"metadata" yaml:"metadata"`
}

Response represents a operation

type ResponseRaw

type ResponseRaw struct {
	Type ResponseType `json:"type" yaml:"type"`

	// Valid only for Sync responses
	Status     string `json:"status" yaml:"status"`
	StatusCode int    `json:"status_code" yaml:"status_code"`

	// Valid only for Async responses
	Operation string `json:"operation" yaml:"operation"`

	// Valid only for Error responses
	Code  int    `json:"error_code" yaml:"error_code"`
	Error string `json:"error" yaml:"error"`

	// Valid for Sync and Error responses
	Metadata interface{} `json:"metadata" yaml:"metadata"`
}

ResponseRaw represents a operation

type ResponseType

type ResponseType string

ResponseType represents a valid response type

const (
	SyncResponse  ResponseType = "sync"
	AsyncResponse ResponseType = "async"
	ErrorResponse ResponseType = "error"
)

Response types

Jump to

Keyboard shortcuts

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