http

package
v0.14.7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package http provides HTTP helper functions and error types.

Index

Constants

View Source
const ErrConflict errors.Kind = "conflict (HTTP Status 409)"

ErrConflict indicates the request contains conflicting data (eg.: duplicated resource)

View Source
const ErrNotFound errors.Kind = "resource not found (HTTP Status 404)"

ErrNotFound indicates the requested resource does not exist in the server.

View Source
const ErrUnexpectedResponseBody errors.Kind = "unexpected API response body"

ErrUnexpectedResponseBody indicates the server responded with an unexpected body.

View Source
const ErrUnexpectedStatus errors.Kind = "unexpected status code"

ErrUnexpectedStatus indicates the server responded with an unexpected status code.

Variables

This section is empty.

Functions

func Delete

func Delete[T resources.Resource](ctx context.Context, client Client, url url.URL) error

Delete requests the endpoint url with a DELETE method.

func Get

func Get[T resources.Resource](ctx context.Context, client Client, u url.URL) (entity T, err error)

Get requests the endpoint components list making a GET request and decode the response into the entity T if validates successfully.

func Patch

func Patch[T resources.Resource](ctx context.Context, client Client, payload interface{}, url url.URL) (entity T, err error)

Patch requests the endpoint components list making a PATCH request and decode the response into the entity T if validates successfully.

func Post

func Post[T resources.Resource](ctx context.Context, client Client, payload any, url url.URL) (entity T, err error)

Post requests the endpoint components list making a POST request and decode the response into the entity T if validates successfully.

func Put

func Put[T resources.Resource](ctx context.Context, client Client, payload interface{}, url url.URL) (entity T, err error)

Put requests the endpoint components list making a PUT request and decode the response into the entity T if validated successfully.

func Request

func Request[T resources.Resource](ctx context.Context, c Client, method string, url url.URL, payload any) (res T, err error)

Request makes a request to the Terramate Cloud using client. The instantiated type gets decoded and return as the entity T, The payload is encoded accordingly to the rules below: - If payload is nil, no body is sent and no Content-Type is set. - If payload is a []byte or string, it is sent as is and the Content-Type is set to text/plain. - If payload is any other type, it is marshaled to JSON and the Content-Type is set to application/json.

Types

type Client

type Client interface {
	HTTPClient() *stdhttp.Client
	Credential() Credential
}

Client is the interface for the HTTP client.

type Credential

type Credential interface {
	// ApplyCredentials applies the credential to the given request.
	ApplyCredentials(req *stdhttp.Request) error

	// RedactCredentials redacts the credential from the given request.
	// This is used for dumping the request without exposing sensitive information.
	RedactCredentials(req *stdhttp.Request)
}

Credential is the interface for the credential providers. Because each provider has its own way to authenticate, the dependency inversion principle is used to abstract the authentication method.

Jump to

Keyboard shortcuts

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