http

package
v0.0.0-...-b110700 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationHeader  = "Authorization"
	ContentTypeHeader    = "Content-Type"
	ContentTypeTextPlain = "text/plain"
	ContentTypeJSON      = "application/json"
)
View Source
const (
	BearerPrefix = "Bearer "
)

Variables

This section is empty.

Functions

func ReadJSON

func ReadJSON(entity any) (io.Reader, error)

func WriteJSON

func WriteJSON(resp *http.Response, entity any) error

func WriteYAML

func WriteYAML(resp *http.Response, entity any) error

Types

type Auth

type Auth struct {
	Basic *BasicAuth
	Token BearerToken
}

func (*Auth) Authenticate

func (auth *Auth) Authenticate(req *http.Request)

type AuthenticatedRoundTripper

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

func NewAuthenticatedRoundTripper

func NewAuthenticatedRoundTripper(
	auth *Auth,
	transport http.RoundTripper,
) *AuthenticatedRoundTripper

func (*AuthenticatedRoundTripper) RoundTrip

func (t *AuthenticatedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

type BearerToken

type BearerToken string

func (BearerToken) String

func (b BearerToken) String() string

type Client

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

func NewClient

func NewClient(ctx context.Context, auth *Auth) *Client

func NewNoAuthClient

func NewNoAuthClient(ctx context.Context) *Client

func (*Client) Context

func (client *Client) Context() context.Context

func (*Client) Delete

func (client *Client) Delete(url string, target any, transformers ...RequestTransformer) error

Delete returns the result of a DELETE request to the specified URL, marshaling the result into target. If the target is nil, the response is discarded.

func (*Client) Get

func (client *Client) Get(url string, target any, transformers ...RequestTransformer) error

Get returns the result of a GET request to the specified URL, marshaled into the target. If the target is nil, the response is discarded.

func (*Client) GetYAML

func (client *Client) GetYAML(url string, target any, transformers ...RequestTransformer) error

Special GET method for YAML content type (used in tests).

func (*Client) Post

func (client *Client) Post(url string, entity, target any, transformers ...RequestTransformer) error

Post returns the result of a POST request to the specified URL, using entity as the body of the request, marshaling the result into target. If the target is nil, the response is discarded.

func (*Client) Put

func (client *Client) Put(url string, entity, target any, transformers ...RequestTransformer) error

Put returns the result of a PUT request to the specified URL, using entity as the body of the request, marshaling the result into target. If the target is nil, the response is discarded.

type RequestTransformer

type RequestTransformer = func(*http.Request)

RequestTransformer is a function that can be used to mutate a request before it is sent (e.g. setting headers).

func WithHost

func WithHost(host string) RequestTransformer

type URL

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

URL is a wrapper around url.URL that provides a fluent API for building URLs.

func NewURL

func NewURL(baseUrl string) (*URL, error)

func (*URL) String

func (u *URL) String() string

String returns the URL as a string.

func (*URL) WithPath

func (u *URL) WithPath(segments ...string) *URL

WithPath appends the given segments to the URL path.

func (*URL) WithQueryParam

func (u *URL) WithQueryParam(k, v string) *URL

WithQueryParam adds the given key-value pair to the URL query.

func (*URL) WithQueryParams

func (u *URL) WithQueryParams(params map[string]string) *URL

WithQueryParams adds the given key-value pairs to the URL query.

Jump to

Keyboard shortcuts

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