httpclient

package
v0.0.0-...-a7b4c27 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewError

func NewError(err error, opts ...ErrorOpt) error

Types

type BaseURLAwareClient

type BaseURLAwareClient interface {
	NewRequest(method, path string, body interface{}) (*http.Request, error)
	Do(req *http.Request, result interface{}) (Status, []byte, error)
}

BaseURLAwareClient is a http client that can build requests not from a full URL, but from a path relative to a configured base url this is useful for REST-APIs that always connect to the same host, but on different paths.

type Client

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

func NewHTTPClient

func NewHTTPClient(baseURL string, client *http.Client) (*Client, error)

NewHTTPClient creates a new client and ensures that the given baseURL ends with a trailing '/'. The trailing '/' is required later for constructing the full URL using a relative path.

func (Client) Do

func (c Client) Do(req *http.Request, result interface{}) (Status, []byte, error)

func (*Client) GetHTTPClient

func (c *Client) GetHTTPClient() *http.Client

func (Client) NewRequest

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

type Error

type Error struct {
	StatusCode int
	Message    string
	Cause      error
}

func (Error) Error

func (e Error) Error() string

Error provides a description of the error including all fields which are initialized to a non-default value.

func (Error) Unwrap

func (e Error) Unwrap() error

type ErrorOpt

type ErrorOpt func(*Error)

func WithMessage

func WithMessage(message string) ErrorOpt

func WithStatusCode

func WithStatusCode(statusCode int) ErrorOpt

type Status

type Status struct {
	Status     string // e.g. "200 OK"
	StatusCode int    // e.g. 200
}

Jump to

Keyboard shortcuts

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