client

package
v0.0.0-...-d2438c5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 15 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 HTTPs.

A client certificate (TLSClientCert) and key (TLSClientKey) must be provided. If connecting to a daemon running in PKI mode, the PKI CA (TLSCA) must also be provided.

Unless the remote server is trusted by the system CA, the remote certificate must be provided (TLSServerCert).

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 WithInsecureSkipVerify

func WithInsecureSkipVerify(insecureSkipVerify bool) Option

WithInsecureSkipVerify sets the insecureSkipVerify 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 WithTLSCA

func WithTLSCA(ca string) Option

WithTLSCA sets the ca on the option

func WithTLSClientCert

func WithTLSClientCert(clientCert string) Option

WithTLSClientCert sets the client cert on the option

func WithTLSClientKey

func WithTLSClientKey(clientKey string) Option

WithTLSClientKey sets the client key on the option

func WithTLSServerCert

func WithTLSServerCert(serverCert string) Option

WithTLSServerCert sets the server cert 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