http

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeleteRequest  = "DELETE"
	GetRequest     = "GET"
	PostRequest    = "POST"
	PutRequest     = "PUT"
	PatchRequest   = "PATCH"
	OptionsRequest = "OPTIONS"
)
View Source
const (
	AcceptAll               = "*/*"
	AuthorizationTypeBasic  = "Basic"
	AuthorizationTypeBearer = "Bearer"
	AuthorizationTypeDigest = "Digest"

	ContentEncodingGzip = "gzip"

	MimeTypeApplicationFormUrlencoded = "application/x-www-form-urlencoded"
	MimeTypeApplicationJson           = "application/json"
	MimeTypeApplicationXml            = "application/xml"
	MimeTypeTextCsv                   = "text/csv"
	MimeTypeTextPlain                 = "text/plain"
)

Variables

This section is empty.

Functions

func GetClientConfigKey

func GetClientConfigKey(name string) string

Types

type CircuitBreakerSettings

type CircuitBreakerSettings struct {
	Enabled          bool          `cfg:"enabled" default:"false"`
	MaxFailures      int64         `cfg:"max_failures" default:"10"`
	RetryDelay       time.Duration `cfg:"retry_delay" default:"1m"`
	ExpectedStatuses []int         `cfg:"expected_statuses"`
}

type CircuitIsOpenError

type CircuitIsOpenError struct {
}

func (CircuitIsOpenError) Error

func (c CircuitIsOpenError) Error() string

type Client

type Client interface {
	Delete(ctx context.Context, request *Request) (*Response, error)
	Get(ctx context.Context, request *Request) (*Response, error)
	Patch(ctx context.Context, request *Request) (*Response, error)
	Post(ctx context.Context, request *Request) (*Response, error)
	Put(ctx context.Context, request *Request) (*Response, error)
	SetTimeout(timeout time.Duration)
	SetUserAgent(ua string)
	SetProxyUrl(p string)
	SetCookies(cs []*http.Cookie)
	SetCookie(c *http.Cookie)
	SetRedirectValidator(allowRequest func(request *http.Request) bool)
	AddRetryCondition(f RetryConditionFunc)
	NewRequest() *Request
	NewJsonRequest() *Request
	NewXmlRequest() *Request
}

func NewCircuitBreakerClientWithInterfaces

func NewCircuitBreakerClientWithInterfaces(baseClient Client, logger log.Logger, clock clock.Clock, name string, settings CircuitBreakerSettings) Client

func NewHttpClientWithInterfaces

func NewHttpClientWithInterfaces(logger log.Logger, clock clock.Clock, metricWriter metric.Writer, httpClient restyClient) Client

func ProvideHttpClient

func ProvideHttpClient(ctx context.Context, config cfg.Config, logger log.Logger, name string) (Client, error)
type Header map[string][]string

type Request

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

func NewJsonRequest

func NewJsonRequest(client Client) *Request

NewJsonRequest creates a request that already contains the application/json content-type, don't create the object inline!

func NewRequest

func NewRequest(client Client) *Request

NewRequest or client.NewRequest() creates a request, don't create the object inline!

func NewXmlRequest

func NewXmlRequest(client Client) *Request

NewXmlRequest creates a request that already contains the application/xml content-type, don't create the object inline!

func (*Request) GetBody

func (r *Request) GetBody() interface{}

func (*Request) GetError

func (r *Request) GetError() error

func (*Request) GetHeader

func (r *Request) GetHeader() Header

func (*Request) GetToken

func (r *Request) GetToken() string

func (*Request) GetUrl

func (r *Request) GetUrl() string

func (*Request) WithAuthToken

func (r *Request) WithAuthToken(token string) *Request

func (*Request) WithBasicAuth

func (r *Request) WithBasicAuth(username string, password string) *Request

func (*Request) WithBody

func (r *Request) WithBody(body interface{}) *Request

func (*Request) WithHeader

func (r *Request) WithHeader(key string, value string) *Request

func (*Request) WithMultipartFile

func (r *Request) WithMultipartFile(param, fileName string, reader io.Reader) *Request

func (*Request) WithMultipartFormData

func (r *Request) WithMultipartFormData(params url.Values) *Request

func (*Request) WithOutputFile

func (r *Request) WithOutputFile(path string) *Request

func (*Request) WithQueryMap

func (r *Request) WithQueryMap(values interface{}) *Request

func (*Request) WithQueryObject

func (r *Request) WithQueryObject(obj interface{}) *Request

func (*Request) WithQueryParam

func (r *Request) WithQueryParam(key string, values ...interface{}) *Request

func (*Request) WithUrl

func (r *Request) WithUrl(rawUrl string) *Request

type Response

type Response struct {
	Body            []byte
	Header          http.Header
	Cookies         []*http.Cookie
	StatusCode      int
	RequestDuration time.Duration
	TotalDuration   *time.Duration
}

type RetryConditionFunc

type RetryConditionFunc func(*Response, error) bool

type Settings

type Settings struct {
	FollowRedirects        bool                   `cfg:"follow_redirects" default:"true"`
	RequestTimeout         time.Duration          `cfg:"request_timeout" default:"30s"`
	RetryCount             int                    `cfg:"retry_count" default:"5"`
	RetryMaxWaitTime       time.Duration          `cfg:"retry_max_wait_time" default:"2000ms"`
	RetryResetReaders      bool                   `cfg:"retry_reset_readers" default:"true"`
	RetryWaitTime          time.Duration          `cfg:"retry_wait_time" default:"100ms"`
	CircuitBreakerSettings CircuitBreakerSettings `cfg:"circuit_breaker"`
}

func UnmarshalClientSettings

func UnmarshalClientSettings(config cfg.Config, name string) Settings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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