Documentation
¶
Index ¶
- Variables
- func BtsIsset(bts []byte) bool
- func ConfigureHeader(req Request, key, value string, override bool) error
- func EncodeBody(payload any, contentType ContentType) (bts []byte, err error)
- func ReadJSON[T any](rc io.ReadCloser) (res T, err error)
- func ReadStream[T any](rc io.ReadCloser, factory StreamFactory[T], fn func(T) bool) (err error)
- func ReadStreamChan[T any](rc io.ReadCloser, factory StreamFactory[T], out chan<- T) (err error)
- func StrIsset(s string) bool
- type CalReqOption
- type Call
- func (c *Call[T]) Call(ctx context.Context) (err error)
- func (c *Call[T]) CallEndpoint(ctx context.Context, e *Endpoint) (err error)
- func (c *Call[T]) Request(opts ...ReqOption) *Call[T]
- func (c *Call[T]) Response(opts ...ResOption) *Call[T]
- func (c *Call[T]) WithAssert(fn func(req Response) error) *Call[T]
- func (c *Call[T]) WithBody(payload any) *Call[T]
- func (c *Call[T]) WithBodyStream(rc io.ReadCloser, bodySize int) *Call[T]
- func (c *Call[T]) WithContentLength(length int) *Call[T]
- func (c *Call[T]) WithContentType(ct ContentType) *Call[T]
- func (c *Call[T]) WithExpectedStatusCodes(states ...int) *Call[T]
- func (c *Call[T]) WithHeader(key, value string, override bool) *Call[T]
- func (c *Call[T]) WithHeaderFunc(fn func() (key, value string, override bool)) *Call[T]
- func (c *Call[T]) WithIgnoreBody() *Call[T]
- func (c *Call[T]) WithJSONEachRow(fn func(T) bool) *Call[T]
- func (c *Call[T]) WithJSONEachRowChan(out chan<- T) *Call[T]
- func (c *Call[T]) WithMethod(method string) *Call[T]
- func (c *Call[T]) WithParseJSON() *Call[T]
- func (c *Call[T]) WithRawBody(payload []byte) *Call[T]
- func (c *Call[T]) WithReadBody() *Call[T]
- func (c *Call[T]) WithStream(factory StreamFactory[T], fn func(T) bool) *Call[T]
- func (c *Call[T]) WithStreamChan(factory StreamFactory[T], ch chan<- T) *Call[T]
- func (c *Call[T]) WithURI(raw string) *Call[T]
- func (c *Call[T]) WithURL(raw string) *Call[T]
- type CallReqOptionFunc
- func WithBody[T any](payload any) CallReqOptionFunc[T]
- func WithBodyStream[T any](rc io.ReadCloser, bodySize int) CallReqOptionFunc[T]
- func WithContentType[T any](ct ContentType) CallReqOptionFunc[T]
- func WithHeader[T any](k, v string, override bool) CallReqOptionFunc[T]
- func WithHeaderFunc[T any](fn func() (string, string, bool)) CallReqOptionFunc[T]
- func WithMethod[T any](method string) CallReqOptionFunc[T]
- func WithRawBody[T any](payload []byte) CallReqOptionFunc[T]
- func WithURI[T any](raw string) CallReqOptionFunc[T]
- func WithURL[T any](raw string) CallReqOptionFunc[T]
- type CallResOption
- type CallResOptionFunc
- func WithAssertion[T any](fn func(res Response) error) CallResOptionFunc[T]
- func WithCloseBody[T any]() CallResOptionFunc[T]
- func WithExpectedStatusCodes[T any](states ...int) CallResOptionFunc[T]
- func WithIgnoredBody[T any]() CallResOptionFunc[T]
- func WithJSON[T any]() CallResOptionFunc[T]
- func WithParseBodyRaw[T any]() CallResOptionFunc[T]
- func WithStream[T any](factory StreamFactory[T], fn func(T) bool) CallResOptionFunc[T]
- func WithStreamChan[T any](factory StreamFactory[T], out chan<- T) CallResOptionFunc[T]
- type ContentType
- type Endpoint
- type FastHttpHttpClientAdapter
- type JSONEachRowStream
- type MockEndpoint
- type MockHttpClientAdapter
- type NativeHttpClientAdapter
- type ReqOption
- type ReqOptionFunc
- type Request
- type ResOption
- type ResOptionFunc
- type Response
- type Stream
- type StreamFactory
- type StreamFactoryFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAssertion = errors.New("assertion was unmet") ErrUnexpectedStatusCode = errors.Wrap(ErrAssertion, "unexpected status code") )
View Source
var (
ContentTypeJSON = "application/json"
)
View Source
var (
ErrUnknownContentType = errors.New("unknown content type")
)
Functions ¶
func EncodeBody ¶ added in v0.2.0
func EncodeBody(payload any, contentType ContentType) (bts []byte, err error)
func ReadStream ¶
func ReadStream[T any](rc io.ReadCloser, factory StreamFactory[T], fn func(T) bool) (err error)
func ReadStreamChan ¶
func ReadStreamChan[T any](rc io.ReadCloser, factory StreamFactory[T], out chan<- T) (err error)
Types ¶
type CalReqOption ¶ added in v0.2.0
type Call ¶
type Call[T any] struct { Req Request Res Response BodyRaw []byte BodyParsed T ReqContentType ContentType ReqBodyRaw []byte // contains filtered or unexported fields }
func (*Call[T]) CallEndpoint ¶ added in v0.2.0
func (*Call[T]) WithAssert ¶
func (*Call[T]) WithBodyStream ¶ added in v0.2.0
func (c *Call[T]) WithBodyStream(rc io.ReadCloser, bodySize int) *Call[T]
WithBodyStream receives a stream of data to set on the request. Second parameter `bodySize` indicates the estimated content-length of this stream. Required when employing fasthttp http client.
func (*Call[T]) WithContentLength ¶ added in v0.2.0
func (c *Call[T]) WithContentLength(length int) *Call[T]
func (*Call[T]) WithContentType ¶ added in v0.2.0
func (c *Call[T]) WithContentType(ct ContentType) *Call[T]
func (*Call[T]) WithExpectedStatusCodes ¶
func (c *Call[T]) WithExpectedStatusCodes(states ...int) *Call[T]
func (*Call[T]) WithHeader ¶
func (*Call[T]) WithHeaderFunc ¶
func (*Call[T]) WithIgnoreBody ¶
func (c *Call[T]) WithIgnoreBody() *Call[T]
func (*Call[T]) WithJSONEachRow ¶
func (c *Call[T]) WithJSONEachRow(fn func(T) bool) *Call[T]
func (*Call[T]) WithJSONEachRowChan ¶
func (c *Call[T]) WithJSONEachRowChan(out chan<- T) *Call[T]
func (*Call[T]) WithMethod ¶
func (c *Call[T]) WithMethod(method string) *Call[T]
func (*Call[T]) WithParseJSON ¶ added in v0.2.0
func (c *Call[T]) WithParseJSON() *Call[T]
func (*Call[T]) WithRawBody ¶
func (c *Call[T]) WithRawBody(payload []byte) *Call[T]
func (*Call[T]) WithReadBody ¶
func (c *Call[T]) WithReadBody() *Call[T]
func (*Call[T]) WithStream ¶
func (c *Call[T]) WithStream(factory StreamFactory[T], fn func(T) bool) *Call[T]
func (*Call[T]) WithStreamChan ¶
func (c *Call[T]) WithStreamChan(factory StreamFactory[T], ch chan<- T) *Call[T]
type CallReqOptionFunc ¶ added in v0.2.0
func WithBodyStream ¶ added in v0.2.0
func WithBodyStream[T any](rc io.ReadCloser, bodySize int) CallReqOptionFunc[T]
func WithContentType ¶ added in v0.2.0
func WithContentType[T any](ct ContentType) CallReqOptionFunc[T]
func WithHeader ¶ added in v0.2.0
func WithHeaderFunc ¶ added in v0.2.0
func WithMethod ¶ added in v0.2.0
func WithRawBody ¶
type CallResOption ¶
type CallResOptionFunc ¶
func WithAssertion ¶
func WithCloseBody ¶
func WithCloseBody[T any]() CallResOptionFunc[T]
func WithExpectedStatusCodes ¶
func WithIgnoredBody ¶
func WithIgnoredBody[T any]() CallResOptionFunc[T]
func WithParseBodyRaw ¶ added in v0.2.0
func WithParseBodyRaw[T any]() CallResOptionFunc[T]
func WithStream ¶
func WithStreamChan ¶
func WithStreamChan[T any](factory StreamFactory[T], out chan<- T) CallResOptionFunc[T]
type ContentType ¶ added in v0.2.0
type ContentType string
func (ContentType) IsJSON ¶ added in v0.2.0
func (c ContentType) IsJSON() bool
func (ContentType) String ¶ added in v0.2.0
func (c ContentType) String() string
type Endpoint ¶
type Endpoint struct {
// contains filtered or unexported fields
}
func NewEndpoint ¶
type FastHttpHttpClientAdapter ¶
type FastHttpHttpClientAdapter struct {
// contains filtered or unexported fields
}
func NewDefaultFastHttpHttpClientAdapter ¶
func NewDefaultFastHttpHttpClientAdapter() *FastHttpHttpClientAdapter
func NewFastHttpHttpClientAdapter ¶
func NewFastHttpHttpClientAdapter(cli *fasthttp.Client) *FastHttpHttpClientAdapter
func (*FastHttpHttpClientAdapter) Request ¶
func (a *FastHttpHttpClientAdapter) Request() (Request, error)
type JSONEachRowStream ¶
type JSONEachRowStream[T any] struct { // contains filtered or unexported fields }
func (*JSONEachRowStream[T]) Data ¶
func (s *JSONEachRowStream[T]) Data() T
func (*JSONEachRowStream[T]) Err ¶
func (s *JSONEachRowStream[T]) Err() error
type MockEndpoint ¶
type MockEndpoint struct {
// contains filtered or unexported fields
}
type MockHttpClientAdapter ¶
type MockHttpClientAdapter struct{}
func NewMockHttpClientAdapter ¶
func NewMockHttpClientAdapter() *MockHttpClientAdapter
func (*MockHttpClientAdapter) Request ¶
func (a *MockHttpClientAdapter) Request() (Request, error)
type NativeHttpClientAdapter ¶
type NativeHttpClientAdapter struct {
// contains filtered or unexported fields
}
func NewDefaultNativeHttpClientAdapter ¶
func NewDefaultNativeHttpClientAdapter() *NativeHttpClientAdapter
func NewNativeHttpClientAdapter ¶
func NewNativeHttpClientAdapter(cli *http.Client) *NativeHttpClientAdapter
func (*NativeHttpClientAdapter) Request ¶
func (a *NativeHttpClientAdapter) Request() (Request, error)
type ReqOption ¶
func WithBaseURL ¶ added in v0.2.0
type ReqOptionFunc ¶
func (ReqOptionFunc) Configure ¶
func (f ReqOptionFunc) Configure(req Request) error
type Request ¶
type Request interface {
SetMethod(string)
SetHeader(k, v string)
AddHeader(k, v string)
SetURL(*url.URL)
// SetBodyStream sets the stream of body data belonging to a request. bodySize parameter is needed
// when using fasthttp implementation.
SetBodyStream(rc io.ReadCloser, bodySize int)
SetBody([]byte)
Body() []byte
BodyStream() io.ReadCloser
URL() *url.URL
}
type ResOption ¶
func WithMockedRes ¶ added in v0.2.0
type ResOptionFunc ¶
func (ResOptionFunc) Parse ¶
func (f ResOptionFunc) Parse(res Response) error
type Response ¶
type Response interface {
Status() int
StatusText() string
Body() io.ReadCloser
SetBody(rc io.ReadCloser)
SetStatus(status int)
}
type StreamFactory ¶
func NewJSONEachRowStreamFactory ¶
func NewJSONEachRowStreamFactory[T any]() StreamFactory[T]
Source Files
¶
Click to show internal directories.
Click to hide internal directories.