clients

package
v3.3.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NoopTokenProvider is a token provider that returns an empty string which is ignored by `DoRequest`.
	NoopTokenProvider = TokenProvider(func() (token string, err error) { return "", nil })
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// Status is the HTTP status of the API response
	Status int
	// Header is the set of response headers
	Header http.Header
	// Response is the response body
	Response []byte
}

APIError describes an error during unsuccessful HTTP request to an API

func (APIError) Error

func (e APIError) Error() string

Error implements the error interface

type BaseAPIClient

type BaseAPIClient interface {
	// GetBaseURL returns the base URL of the service which can be used in HTTP request tasks.
	GetBaseURL() string
	// DoRequest performs the HTTP request with the given parameters, marshals the payload and
	// unmarshals the response into the given output if the status code is successful
	DoRequest(ctx context.Context, method, path string, query url.Values, payload, out interface{}) error
}

BaseAPIClient describes all basic HTTP client operations required to work with a JSON API

func NewBaseAPIClient

func NewBaseAPIClient(basePath, tokenHeaderName string, tokenProvider TokenProvider, client *http.Client, debug bool) BaseAPIClient

NewBaseAPIClient creates a new instance of the base API client implementation. Never use `debug=true` in production environments, it will leak sensitive data

type TokenProvider

type TokenProvider func() (token string, err error)

TokenProvider is a function that gets the token string for each request

func TokenProviderFromCreator

func TokenProviderFromCreator(tc tokens.Creator, reference string, opts tokens.Options) TokenProvider

TokenProviderFromCreator creates a token provider out of token creator.

Jump to

Keyboard shortcuts

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