api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package api provides commmon functionality for the OTF API

Index

Constants

View Source
const (
	DefaultBasePath = "/otfapi"
	PingEndpoint    = "ping"
	DefaultAddress  = "localhost:8080"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.1.15

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

func NewClient added in v0.1.15

func NewClient(config Config) (*Client, error)

func (*Client) Do added in v0.1.15

func (c *Client) Do(ctx context.Context, req *retryablehttp.Request, v interface{}) error

Do sends an API request and returns the API response. The API response is JSONAPI decoded and the document's primary data is stored in the value pointed to by v, or returned as an error if an API error has occurred.

If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) Hostname added in v0.1.15

func (c *Client) Hostname() string

Hostname returns the server host:port.

func (*Client) NewRequest added in v0.1.15

func (c *Client) NewRequest(method, path string, v interface{}) (*retryablehttp.Request, error)

NewRequest creates an API request with proper headers and serialization.

A relative URL path can be provided, in which case it is resolved relative to the baseURL of the Client. Relative URL paths should always be specified without a preceding slash. Adding a preceding slash allows for ignoring the configured baseURL for non-standard endpoints.

If v is supplied, the value will be JSONAPI encoded and included as the request body. If the method is GET, the value will be parsed and added as query parameters.

type Config added in v0.1.15

type Config struct {
	// The address of the otf API.
	Address string
	// The base path on which the API is served.
	BasePath string
	// API token used to access the otf API.
	Token string
	// Headers that will be added to every request.
	Headers http.Header
	// Toggle retrying requests upon encountering transient errors.
	RetryRequests bool
	// RetryLogHook is invoked each time a request is retried.
	RetryLogHook retryablehttp.RequestLogHook
	// Override default http transport
	Transport http.RoundTripper
}

Config provides configuration details to the API client.

type Handlers added in v0.1.15

type Handlers struct{}

func (*Handlers) AddHandlers added in v0.1.15

func (h *Handlers) AddHandlers(r *mux.Router)

Jump to

Keyboard shortcuts

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