httputils

package module
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 20 Imported by: 0

README

go-httputils

Some go http utils

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPClientDefaultConfig = HTTPClientConfig{
	// contains filtered or unexported fields
}

Functions

func IsNotFound added in v0.0.21

func IsNotFound(err error) bool

Types

type BasicAuthTransport added in v0.0.9

type BasicAuthTransport struct {
	Username, Password string
	Transport          http.RoundTripper
}

func (*BasicAuthTransport) RoundTrip added in v0.0.9

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

type BearerAuthTransport added in v0.0.9

type BearerAuthTransport struct {
	Token     string
	Transport http.RoundTripper
}

func (*BearerAuthTransport) RoundTrip added in v0.0.9

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

type CallLogger added in v0.0.6

type CallLogger func(r *http.Request, resp *http.Response, start time.Time, err error)

type Decoder added in v0.0.5

type Decoder func([]byte, interface{}) error

type Encoder added in v0.0.5

type Encoder func(interface{}) ([]byte, error)

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(opts ...HTTPClientConfigOpt) *HTTPClient

func (*HTTPClient) Delete added in v0.0.12

func (client *HTTPClient) Delete(url string, params ...RequestParam) error

func (*HTTPClient) DeleteForBody added in v0.0.31

func (client *HTTPClient) DeleteForBody(url string, requestBody interface{}, responseBody interface{}, params ...RequestParam) error

func (*HTTPClient) Get

func (client *HTTPClient) Get(url string, entity interface{}, params ...RequestParam) error

func (*HTTPClient) Head added in v0.0.22

func (client *HTTPClient) Head(url string, params ...RequestParam) error

func (*HTTPClient) Patch

func (client *HTTPClient) Patch(url string, requestBody interface{}, params ...RequestParam) error

func (*HTTPClient) PatchForBody

func (client *HTTPClient) PatchForBody(url string, requestBody interface{}, responseBody interface{}, params ...RequestParam) error

func (*HTTPClient) Post

func (client *HTTPClient) Post(url string, requestBody interface{}, params ...RequestParam) error

func (*HTTPClient) PostForBody

func (client *HTTPClient) PostForBody(url string, requestBody interface{}, responseBody interface{}, params ...RequestParam) error

func (*HTTPClient) PostForLocation added in v0.0.13

func (client *HTTPClient) PostForLocation(url string, requestBody interface{}, params ...RequestParam) (string, error)

func (*HTTPClient) PostForLocationAndBody added in v0.0.16

func (client *HTTPClient) PostForLocationAndBody(
	url string,
	requestBody interface{},
	responseBody interface{},
	params ...RequestParam,
) (string, error)

func (*HTTPClient) Put

func (client *HTTPClient) Put(url string, requestBody interface{}, params ...RequestParam) error

func (*HTTPClient) PutForBody added in v0.0.17

func (client *HTTPClient) PutForBody(url string, requestBody interface{}, responseBody interface{}, params ...RequestParam) error

type HTTPClientConfig

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

type HTTPClientConfigOpt

type HTTPClientConfigOpt func(config *HTTPClientConfig)

func BaseURL added in v0.0.24

func BaseURL(url string) HTTPClientConfigOpt

func CacheSize

func CacheSize(size uint64) HTTPClientConfigOpt

func DisableCache

func DisableCache() HTTPClientConfigOpt

func LogCalls added in v0.0.6

func LogCalls(logger CallLogger) HTTPClientConfigOpt

func MaxRetries

func MaxRetries(retries uint64) HTTPClientConfigOpt

func NoRetries

func NoRetries() HTTPClientConfigOpt

func SetCheckRedirect added in v0.0.32

func SetCheckRedirect(check func(req *http.Request, via []*http.Request) error) HTTPClientConfigOpt

func SetGetBackoffCreator added in v0.0.18

func SetGetBackoffCreator(creator func() backoff.BackOff) HTTPClientConfigOpt

func SetOtherBackoffCreator added in v0.0.18

func SetOtherBackoffCreator(creator func() backoff.BackOff) HTTPClientConfigOpt

func TLSConfig added in v0.0.7

func TLSConfig(tlsConfig *tls.Config) HTTPClientConfigOpt

func Timeout

func Timeout(timeout time.Duration) HTTPClientConfigOpt

func UseBasicAuth added in v0.0.9

func UseBasicAuth(username, password string) HTTPClientConfigOpt

func UseBearerAuth added in v0.0.8

func UseBearerAuth(token string) HTTPClientConfigOpt

func UseOAuth2 added in v0.0.4

func UseOAuth2(source oauth2.TokenSource) HTTPClientConfigOpt

type HTTPClientError

type HTTPClientError struct {
	Code   int
	Status string
}

func AsHTTPClientError added in v0.0.21

func AsHTTPClientError(err error) (HTTPClientError, bool)

func (HTTPClientError) Error

func (err HTTPClientError) Error() string

type Request added in v0.0.5

type Request struct {
	RawRequest *http.Request
	Header     http.Header
	Encode     Encoder

	StreamDecoder StreamDecoder
	Decode        Decoder
	RawResponse   *http.Response
	// contains filtered or unexported fields
}

type RequestParam

type RequestParam func(*Request)

func Accept

func Accept(mediaType string) RequestParam

func BasicAuth added in v0.0.15

func BasicAuth(username, password string) RequestParam

func BearerAuth

func BearerAuth(token string) RequestParam

func ClientToken deprecated

func ClientToken(token string) RequestParam

ClientToken set the "Client-Token" header

Deprecated: The use of the non-standard "Client-Token" header is deprecated. Use the "Authorization" header instead. See `BearerAuth(…)`

func ContentType added in v0.0.5

func ContentType(contentType string) RequestParam

func Context added in v0.0.26

func Context(ctx context.Context) RequestParam

func SetDecoder added in v0.0.5

func SetDecoder(d Decoder) RequestParam

func SetEncoder added in v0.0.5

func SetEncoder(e Encoder) RequestParam

func SetHeader added in v0.0.31

func SetHeader(name, value string) RequestParam

func SetStreamDecoder added in v0.0.27

func SetStreamDecoder(d StreamDecoder) RequestParam

func UseRawDecoder added in v0.0.19

func UseRawDecoder() RequestParam

func UseRawEncoder added in v0.0.19

func UseRawEncoder() RequestParam

func UserAgent

func UserAgent(userAgent string) RequestParam

type StreamDecoder added in v0.0.27

type StreamDecoder func(io.Reader, interface{}) error

Jump to

Keyboard shortcuts

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