go_http_client

package module
v0.0.0-...-3a4f557 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 10 Imported by: 0

README

Simple Go Http Client

An API client base.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResponseValidator

func ResponseValidator(resp *http.Response) error

Types

type Client

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

func NewClient

func NewClient(endpoint string, options ...Option) *Client

func (*Client) DoRequest

func (c *Client) DoRequest(ctx context.Context, method, path string, parser ResponseParser, options ...RequestOption) error

func (*Client) DoRequestJson

func (c *Client) DoRequestJson(ctx context.Context, method, path string, intf interface{}, options ...RequestOption) error

func (*Client) DoRequestNoBody

func (c *Client) DoRequestNoBody(ctx context.Context, method, path string, options ...RequestOption) error

func (*Client) DoRequestString

func (c *Client) DoRequestString(ctx context.Context, method, path string, out *string, options ...RequestOption) error

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, method, path string, wr io.Writer, options ...RequestOption) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, options ...RequestOption) error

func (*Client) GetJson

func (c *Client) GetJson(ctx context.Context, path string, intf interface{}, options ...RequestOption) error

type Option

type Option func(*Client)

func RequestBasicAuthOption

func RequestBasicAuthOption(username, password string) Option

RequestBasicAuthOption add basic credentials to all the requests

func WithDebug

func WithDebug(b bool) Option

WithDebug enable debugging for the client

func WithHttpClient

func WithHttpClient(client httpClient) Option

WithHttpClient setup a custom http client

func WithLog

func WithLog(l *log.Logger) Option

WithRequestFilters setup a custom logger

func WithRequestOptions

func WithRequestOptions(fn ...RequestOption) Option

WithRequestFilters add filters which will be applied to all the requests

func WithResponseValidator

func WithResponseValidator(v ValidateResponse) Option

WithResponseValidator set a custom response validator function

type RequestOption

type RequestOption func(*http.Request) error

func WithBodyOpt

func WithBodyOpt(body io.Reader) RequestOption

RequestBodyOption add body to a request

func WithHeadersOpt

func WithHeadersOpt(header http.Header) RequestOption

WithHeadersOpt add headers to a request

func WithQueryOpt

func WithQueryOpt(query url.Values) RequestOption

WithQueryOpt add query to request

type ResponseParser

type ResponseParser func(*http.Response) error

func JsonParser

func JsonParser(dst interface{}) ResponseParser

func NoBodyParser

func NoBodyParser(log *log.Logger) ResponseParser

func RawBodyParser

func RawBodyParser(dst *[]byte) ResponseParser

func RawStringParser

func RawStringParser(dst *string) ResponseParser

type StatusCodeError

type StatusCodeError struct {
	Code   int
	Status string
	Body   string
}

StatusCodeError represents an http response error

func (StatusCodeError) Error

func (t StatusCodeError) Error() string

func (StatusCodeError) HTTPStatusCode

func (t StatusCodeError) HTTPStatusCode() int

type ValidateResponse

type ValidateResponse func(*http.Response) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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