api

package
v0.0.0-...-8caf421 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderKeyAccept is key for  Accept
	HeaderKeyAccept = "Accept"
	// HeaderKeyContentType is key for Content-Type
	HeaderKeyContentType = "Content-Type"
	// HeaderValContentTypeJSON is key for application/json
	HeaderValContentTypeJSON = "application/json"
)

Variables

This section is empty.

Functions

func WriteIndented

func WriteIndented(w io.Writer, b []byte) error

WriteIndented indents all lines four spaces.

func WriteIndentedN

func WriteIndentedN(w io.Writer, b []byte, n int) error

WriteIndentedN indents all lines n spaces.

Types

type Client

type Client interface {

	// Do sends an HTTP request to the API.
	Do(
		ctx context.Context,
		method, path string,
		body, resp interface{}) error

	// DoWithHeaders sends an HTTP request to the API.
	DoWithHeaders(
		ctx context.Context,
		method, path string,
		headers map[string]string,
		body, resp interface{}) error

	// DoandGetREsponseBody sends an HTTP reqeust to the API and returns
	// the raw response body
	DoAndGetResponseBody(
		ctx context.Context,
		method, path string,
		headers map[string]string,
		body interface{}) (*http.Response, error)

	// DoandGetResponseBodyAuthorized sends an HTTP reqeust to the API and returns
	// the raw response body [Already available auth token is getting used]
	DoAndGetResponseBodyAuthorized(
		ctx context.Context,
		method, path string,
		headers map[string]string,
		body interface{}) (*http.Response, error)

	// Get sends an HTTP request using the GET method to the API.
	Get(
		ctx context.Context,
		path string,
		headers map[string]string,
		resp interface{}) error

	// Post sends an HTTP request using the POST method to the API.
	Post(
		ctx context.Context,
		path string,
		headers map[string]string,
		body, resp interface{}) error

	// Put sends an HTTP request using the PUT method to the API.
	Put(
		ctx context.Context,
		path string,
		headers map[string]string,
		body, resp interface{}) error

	// Delete sends an HTTP request using the DELETE method to the API.
	Delete(
		ctx context.Context,
		path string,
		headers map[string]string,
		resp interface{}) error

	// SetToken sets the Auth token for the HTTP client
	SetToken(token string)

	// GetToken gets the Auth token for the HTTP client
	GetToken() string

	// ParseJSONError parses the JSON in r into an error object
	ParseJSONError(r *http.Response) error
}

Client is an API client.

func New

func New(
	ctx context.Context,
	host string,
	opts ClientOptions,
	debug bool) (Client, error)

New returns a new API client.

type ClientOptions

type ClientOptions struct {
	// Insecure is a flag that indicates whether or not to supress SSL errors.
	Insecure bool

	// UseCerts is a flag that indicates whether system certs should be loaded
	UseCerts bool

	// Timeout specifies a time limit for requests made by this client.
	Timeout time.Duration

	// ShowHTTP is a flag that indicates whether or not HTTP requests and
	// responses should be logged to stdout
	ShowHTTP bool
}

ClientOptions are options for the API client.

Jump to

Keyboard shortcuts

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