clientutil

package
v0.0.0-...-b178995 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlobNotFound = errors.New("blob not found")
View Source
var ErrNotFound = errors.New("not found")

Functions

func Decode

func Decode(resp *http.Response) ([]byte, error)

func EnableJSON

func EnableJSON() func(*http.Request) error

func EnableMsgpack

func EnableMsgpack() func(*http.Request) error

func EnableSnappyEncoding

func EnableSnappyEncoding() func(*http.Request) error

func NewSnappyResponseReader

func NewSnappyResponseReader(resp *http.Response) io.ReadCloser

func Unmarshal

func Unmarshal(resp *http.Response, out interface{}) error

func WithAPIKey

func WithAPIKey(apiKey string) func(*http.Request) error

func WithHeader

func WithHeader(name, value string) func(*http.Request) error

func WithHeaders

func WithHeaders(headers map[string]string) func(*http.Request) error

func WithNamespace

func WithNamespace(ns string) func(*http.Request) error

func WithQueryArg

func WithQueryArg(name, value string) func(*http.Request) error

func WithQueryArgs

func WithQueryArgs(query map[string]string) func(*http.Request) error

func WithUserAgent

func WithUserAgent(ua string) func(*http.Request) error

Types

type BadStatusCodeError

type BadStatusCodeError struct {
	Expected           int
	ResponseStatusCode int
	ResponseBody       []byte
	RequestMethod      string
	RequestURL         string

	// In case it failed before getting the response
	Err error
}

func ExpectStatusCode

func ExpectStatusCode(resp *http.Response, status int) *BadStatusCodeError

func (*BadStatusCodeError) Error

func (e *BadStatusCodeError) Error() string

func (*BadStatusCodeError) IsNotFound

func (e *BadStatusCodeError) IsNotFound() (res bool)

func (*BadStatusCodeError) IsUnauthorized

func (e *BadStatusCodeError) IsUnauthorized() (res bool)

type Caps

type Caps struct {
	ReplicationEnabled bool `json:"replication_enabled"`
}

type Client

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

func New

func New(opts *Opts) *Client

New initializes an HTTP client

func (*Client) DoReq

func (client *Client) DoReq(ctx context.Context, method, path string, headers map[string]string, body io.Reader) (*http.Response, error)

DoReq "do" the request and returns the `*http.Response`

func (*Client) DoReqWithQuery

func (client *Client) DoReqWithQuery(ctx context.Context, method, path string, query map[string]string, headers map[string]string, body io.Reader) (*http.Response, error)

DoReq "do" the request and returns the `*http.Response`

func (*Client) GetJSON

func (client *Client) GetJSON(ctx context.Context, path string, headers map[string]string, out interface{}) error

func (*Client) Opts

func (client *Client) Opts() *Opts

Opts returns the current opts

func (*Client) SessionID

func (client *Client) SessionID() string

ClientID returns a unique "session ID" that won't change for the lifetime of the client

type ClientUtil

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

func NewClientUtil

func NewClientUtil(host string, options ...func(*http.Request) error) *ClientUtil

New initializes an HTTP client

func (*ClientUtil) Capabilities

func (client *ClientUtil) Capabilities() (*Caps, error)

func (*ClientUtil) CheckAuth

func (client *ClientUtil) CheckAuth() (bool, error)

func (*ClientUtil) Delete

func (client *ClientUtil) Delete(path string, options ...func(*http.Request) error) (*http.Response, error)

func (*ClientUtil) Do

func (client *ClientUtil) Do(method, path string, body io.Reader, options ...func(*http.Request) error) (*http.Response, error)

DoReq "do" the request and returns the `*http.Response`

func (*ClientUtil) Get

func (client *ClientUtil) Get(path string, options ...func(*http.Request) error) (*http.Response, error)

func (*ClientUtil) Head

func (client *ClientUtil) Head(path string, options ...func(*http.Request) error) (*http.Response, error)

func (*ClientUtil) PatchJSON

func (client *ClientUtil) PatchJSON(path string, payload interface{}, options ...func(*http.Request) error) (*http.Response, error)

func (*ClientUtil) PatchMsgpack

func (client *ClientUtil) PatchMsgpack(path string, payload interface{}, options ...func(*http.Request) error) (*http.Response, error)

func (*ClientUtil) Post

func (client *ClientUtil) Post(path string, data []byte, options ...func(*http.Request) error) (*http.Response, error)

func (*ClientUtil) PostJSON

func (client *ClientUtil) PostJSON(path string, payload interface{}, options ...func(*http.Request) error) (*http.Response, error)

func (*ClientUtil) PostMsgpack

func (client *ClientUtil) PostMsgpack(path string, payload interface{}, options ...func(*http.Request) error) (*http.Response, error)

type Opts

type Opts struct {
	Host   string // BlobStash host (with proto and without trailing slash) e.g. "https://blobtash.com"
	APIKey string // BlobStash API key

	Namespace string // BlobStash namespace

	Headers   map[string]string // Headers added to each request
	UserAgent string            // Custom User-Agent

	SnappyCompression bool // Enable snappy compression for the HTTP requests
}

Opts holds the client configuration

func (*Opts) SetHost

func (opts *Opts) SetHost(host, apiKey string) *Opts

SetHost is a configuration shortcut for setting the API hostname and the API key

func (*Opts) SetNamespace

func (opts *Opts) SetNamespace(ns string) *Opts

SetNamespace is a shortcut for setting the namespace at the client level

Jump to

Keyboard shortcuts

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