httpcall

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package httpcall takes boilerplate out of typical non-streaming HTTP API calls.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMaxResponseLength int64         = 100 * 1024 * 1024 // 100 MB seems like a fine safety limit
	DefaultRetryDelay        time.Duration = 500 * time.Millisecond
)
View Source
var (
	ErrResponseTooLong = errors.New("response too long")
)

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

type Error

type Error struct {
	CallID            string
	IsNetwork         bool
	IsRetriable       bool
	RetryDelay        time.Duration
	StatusCode        int
	Type              string
	Path              string
	Message           string
	RawResponseBody   []byte
	PrintResponseBody bool
	Cause             error
	Category1         *ErrorCategory
	Category2         *ErrorCategory
}

func (*Error) AddCategory

func (e *Error) AddCategory(cat *ErrorCategory) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) IsInCategory

func (e *Error) IsInCategory(cat *ErrorCategory) bool

func (*Error) IsUnprocessableEntity

func (e *Error) IsUnprocessableEntity() bool

func (*Error) ShortError

func (e *Error) ShortError() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorCategory

type ErrorCategory struct {
	Name string
}

func (*ErrorCategory) Error

func (err *ErrorCategory) Error() string

type Request

type Request struct {
	Context context.Context
	CallID  string

	Method                 string
	BaseURL                string
	Path                   string
	PathParams             map[string]string
	QueryParams            url.Values
	FullURLOverride        string // for APIs using REST-style links, completely overrides BaseURL, Path and QueryParams
	Input                  any
	RawRequestBody         []byte
	RequestBodyContentType string
	Headers                http.Header
	BasicAuth              BasicAuth
	HTTPRequest            *http.Request

	OutputPtr         any
	MaxResponseLength int64

	HTTPClient     *http.Client
	MaxAttempts    int
	RetryDelay     time.Duration
	LastRetryDelay time.Duration

	ShouldStart        func(r *Request) error
	Started            func(r *Request)
	ValidateOutput     func() error
	ParseResponse      func(r *Request) error
	ParseErrorResponse func(r *Request)
	Failed             func(r *Request)
	Finished           func(r *Request)

	UserObject any
	UserData   map[string]any

	Attempts        int
	HTTPResponse    *http.Response
	RawResponseBody []byte
	Error           *Error
	Duration        time.Duration
	// contains filtered or unexported fields
}

func (*Request) Clone added in v0.3.1

func (r *Request) Clone() *Request

func (*Request) Curl

func (r *Request) Curl() string

func (*Request) Do

func (r *Request) Do() error

func (*Request) Init

func (r *Request) Init()

func (*Request) IsIdempotent

func (r *Request) IsIdempotent() bool

func (*Request) OnFailed

func (r *Request) OnFailed(f func(r *Request))

func (*Request) OnFinished

func (r *Request) OnFinished(f func(r *Request))

func (*Request) OnShouldStart

func (r *Request) OnShouldStart(f func(r *Request) error)

func (*Request) OnStarted

func (r *Request) OnStarted(f func(r *Request))

func (*Request) OnValidate

func (r *Request) OnValidate(f func() error)

func (*Request) SetHeader added in v0.3.1

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

func (*Request) StatusCode

func (r *Request) StatusCode() int

Jump to

Keyboard shortcuts

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