https

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: MIT Imports: 18 Imported by: 11

Documentation

Index

Constants

View Source
const ACCEPT_HEADER = "accept"
View Source
const AUTHORIZATION_HEADER = "authorization"
View Source
const CONTENT_LENGTH_HEADER = "content-length"
View Source
const CONTENT_TYPE_HEADER = "content-type"
View Source
const FORM_URLENCODED_CONTENT_TYPE = "application/x-www-form-urlencoded"
View Source
const JSON_CONTENT_TYPE = "application/json"
View Source
const MULTIPART_CONTENT_TYPE = "multipart/form-data"
View Source
const TEXT_CONTENT_TYPE = "text/plain; charset=utf-8"
View Source
const XML_CONTENT_TYPE = "application/xml"

Variables

This section is empty.

Functions

func GetTestingServer

func GetTestingServer() *httptest.Server

func MergeHeaders

func MergeHeaders(headers, headersToMerge map[string]string)

func ReadBytes

func ReadBytes(input io.Reader) ([]byte, error)

func SetHeaders

func SetHeaders(headers map[string]string, name, value string)

Types

type ApiResponse

type ApiResponse[T any] struct {
	Data     T              `json:"data"`
	Response *http.Response `json:"response"`
}

func NewApiResponse

func NewApiResponse[T any](data T, response *http.Response) ApiResponse[T]

type Authenticator

type Authenticator func(bool) HttpInterceptor

type CallBuilder

type CallBuilder interface {
	AppendPath(path string)
	AppendTemplateParam(param string)
	AppendTemplateParams(params interface{})
	BaseUrl(arg string)
	Method(httpMethodName string)

	Accept(acceptHeaderValue string)
	ContentType(contentTypeHeaderValue string)
	Header(name string, value interface{})
	CombineHeaders(headersToMerge map[string]string)
	QueryParam(name string, value interface{})

	QueryParams(parameters map[string]interface{})
	FormParam(name string, value interface{})

	FormData(fields []FormParam)

	Text(body string)
	FileStream(file FileWrapper)
	Json(data interface{})

	InterceptRequest(interceptor func(httpRequest *http.Request) *http.Request)

	Call() (*HttpContext, error)
	CallAsJson() (*json.Decoder, *http.Response, error)
	CallAsText() (string, *http.Response, error)
	CallAsStream() ([]byte, *http.Response, error)
	Authenticate(requiresAuth bool)
	RequestRetryOption(option RequestRetryOption)
	// contains filtered or unexported methods
}

type CallBuilderFactory

type CallBuilderFactory func(httpMethod, path string) CallBuilder

func CreateCallBuilderFactory

func CreateCallBuilderFactory(
	baseUrlProvider baseUrlProvider,
	auth Authenticator,
	httpClient HttpClient,
	retryConfig RetryConfiguration,
) CallBuilderFactory

type FileWrapper

type FileWrapper struct {
	File        []byte
	FileName    string
	FileHeaders http.Header
}

func GetFile

func GetFile(fileUrl string) (FileWrapper, error)

type FormParam added in v0.0.11

type FormParam struct {
	Key     string
	Value   any
	Headers http.Header
}

type HttpCallExecutor

type HttpCallExecutor func(request *http.Request) HttpContext

func CallHttpInterceptors

func CallHttpInterceptors(
	interceptors []HttpInterceptor,
	client HttpCallExecutor,
) HttpCallExecutor

type HttpClient

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

func NewHttpClient

func NewHttpClient(httpConfig HttpConfiguration) HttpClient

func (*HttpClient) Execute

func (c *HttpClient) Execute(request *http.Request) (*http.Response, error)

type HttpClientInterface

type HttpClientInterface interface {
	Execute(request *http.Request) *http.Response
}

type HttpConfiguration

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

func NewHttpConfiguration

func NewHttpConfiguration(options ...HttpConfigurationOptions) HttpConfiguration

func (*HttpConfiguration) RetryConfiguration

func (h *HttpConfiguration) RetryConfiguration() RetryConfiguration

func (*HttpConfiguration) Timeout

func (h *HttpConfiguration) Timeout() float64

func (*HttpConfiguration) Transport

func (h *HttpConfiguration) Transport() http.RoundTripper

type HttpConfigurationOptions

type HttpConfigurationOptions func(*HttpConfiguration)

func WithRetryConfiguration

func WithRetryConfiguration(retryConfig RetryConfiguration) HttpConfigurationOptions

func WithTimeout

func WithTimeout(timeout float64) HttpConfigurationOptions

func WithTransport

func WithTransport(transport http.RoundTripper) HttpConfigurationOptions

type HttpContext

type HttpContext struct {
	Request  *http.Request
	Response *http.Response
}

func PassThroughInterceptor

func PassThroughInterceptor(
	req *http.Request,
	next HttpCallExecutor,
) HttpContext

type HttpInterceptor

type HttpInterceptor func(request *http.Request, next HttpCallExecutor) HttpContext

type RequestRetryOption

type RequestRetryOption int
const (
	Default RequestRetryOption = iota
	Enable
	Disable
)

func (RequestRetryOption) String

func (r RequestRetryOption) String() string

type RetryConfiguration

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

func NewRetryConfiguration

func NewRetryConfiguration(options ...RetryConfigurationOptions) RetryConfiguration

func (*RetryConfiguration) BackoffFactor

func (r *RetryConfiguration) BackoffFactor() int64

func (*RetryConfiguration) GetRetryWaitTime

func (rc *RetryConfiguration) GetRetryWaitTime(
	maxWaitTime time.Duration,
	retryCount int64,
	response *http.Response,
	timeoutError error) time.Duration

func (*RetryConfiguration) HttpMethodsToRetry

func (r *RetryConfiguration) HttpMethodsToRetry() []string

func (*RetryConfiguration) HttpStatusCodesToRetry

func (r *RetryConfiguration) HttpStatusCodesToRetry() []int64

func (*RetryConfiguration) MaxRetryAttempts

func (r *RetryConfiguration) MaxRetryAttempts() int64

func (*RetryConfiguration) MaximumRetryWaitTime

func (r *RetryConfiguration) MaximumRetryWaitTime() time.Duration

func (*RetryConfiguration) RetryInterval

func (r *RetryConfiguration) RetryInterval() time.Duration

func (*RetryConfiguration) RetryOnTimeout

func (r *RetryConfiguration) RetryOnTimeout() bool

func (*RetryConfiguration) ShouldRetry

func (rc *RetryConfiguration) ShouldRetry(retryRequestOption RequestRetryOption, httpMethod string) bool

type RetryConfigurationOptions

type RetryConfigurationOptions func(*RetryConfiguration)

func WithBackoffFactor

func WithBackoffFactor(backoffFactor int64) RetryConfigurationOptions

func WithHttpMethodsToRetry

func WithHttpMethodsToRetry(httpMethodsToRetry []string) RetryConfigurationOptions

func WithHttpStatusCodesToRetry

func WithHttpStatusCodesToRetry(httpStatusCodesToRetry []int64) RetryConfigurationOptions

func WithMaxRetryAttempts

func WithMaxRetryAttempts(maxRetryAttempts int64) RetryConfigurationOptions

func WithMaximumRetryWaitTime

func WithMaximumRetryWaitTime(maximumRetryWaitTime time.Duration) RetryConfigurationOptions

func WithRetryInterval

func WithRetryInterval(retryInterval time.Duration) RetryConfigurationOptions

func WithRetryOnTimeout

func WithRetryOnTimeout(retryOnTimeout bool) RetryConfigurationOptions

Jump to

Keyboard shortcuts

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