recv

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 9 Imported by: 6

Documentation

Overview

Package recv defines a pure computations to compose HTTP response receivers

Index

Constants

View Source
const (
	Age              = HeaderOf[int]("Age")
	CacheControl     = HeaderOf[string]("Cache-Control")
	Connection       = HeaderEnumConnection("Connection")
	ContentEncoding  = HeaderOf[string]("Content-Encoding")
	ContentLanguage  = HeaderOf[string]("Content-Language")
	ContentLength    = HeaderOf[int]("Content-Length")
	ContentLocation  = HeaderOf[string]("Content-Location")
	ContentMD5       = HeaderOf[string]("Content-MD5")
	ContentRange     = HeaderOf[string]("Content-Range")
	ContentType      = HeaderEnumContent("Content-Type")
	Date             = HeaderOf[time.Time]("Date")
	ETag             = HeaderOf[string]("ETag")
	Expires          = HeaderOf[time.Time]("Expires")
	LastModified     = HeaderOf[time.Time]("Last-Modified")
	Link             = HeaderOf[string]("Link")
	Location         = HeaderOf[string]("Location")
	RetryAfter       = HeaderOf[time.Time]("Retry-After")
	Server           = HeaderOf[string]("Server")
	SetCookie        = HeaderOf[string]("Set-Cookie")
	TransferEncoding = HeaderEnumTransferEncoding("Transfer-Encoding")
	Via              = HeaderOf[string]("Via")
)

List of supported HTTP header constants https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Response_fields

View Source
const Status = StatusCode(0)

Status is collection of constants for HTTP Status Code checks

ƒ.Status.OK
ƒ.Status.NotFound

Variables

This section is empty.

Functions

func Body added in v2.5.0

func Body[T any](out *T) http.Arrow

Body applies auto decoders for response and returns either binary or native Go data structure. The Content-Type header give a hint to decoder. Supply the pointer to data target data structure.

func Bytes

func Bytes(w io.Writer) http.Arrow

Bytes receive raw binary from HTTP response

func Code

func Code(code ...http.StatusCode) http.Arrow

Code is a mandatory statement to match expected HTTP Status Code against received one. The execution fails StatusCode error if service responds with other value then specified one.

func Expect added in v2.4.0

func Expect[T any](expect T) http.Arrow

Match received payload to defined pattern

func Header[T http.MatchableHeaderValues](header string, value T) http.Arrow

Header matches or lifts header value

func Match added in v2.1.0

func Match(val string) http.Arrow

Match received payload to defined pattern

func Recv

func Recv[T any](out *T) http.Arrow

Recv is alias for Body, maintained only for compatibility

func Try added in v2.7.0

func Try(arrow http.Arrow) http.Arrow

Try catches error of http.Arrow, allowing to implement optional constraints

Types

type HeaderEnumConnection

type HeaderEnumConnection string

Type of HTTP Header, Connection enumeration

const Connection = HeaderEnumConnection("Connection")
ƒ.Connection.KeepAlive

func (HeaderEnumConnection) Any

func (h HeaderEnumConnection) Any(ctx *http.Context) error

Matches header to any value

func (HeaderEnumConnection) Close

func (h HeaderEnumConnection) Close(ctx *http.Context) error

Close defines header `???: close`

func (HeaderEnumConnection) Is

func (h HeaderEnumConnection) Is(value string) http.Arrow

Matches value of HTTP header

func (HeaderEnumConnection) KeepAlive

func (h HeaderEnumConnection) KeepAlive(ctx *http.Context) error

KeepAlive defines header `???: keep-alive`

func (HeaderEnumConnection) To

func (h HeaderEnumConnection) To(value *string) http.Arrow

Matches value of HTTP header

type HeaderEnumContent

type HeaderEnumContent string

Type of HTTP Header, Content-Type enumeration

const ContentType = HeaderEnumContent("Content-Type")
ƒ.ContentType.JSON

func (HeaderEnumContent) Any

func (h HeaderEnumContent) Any(ctx *http.Context) error

Matches header to any value

func (HeaderEnumContent) ApplicationJSON

func (h HeaderEnumContent) ApplicationJSON(ctx *http.Context) error

ApplicationJSON defines header `???: application/json`

func (HeaderEnumContent) Form

func (h HeaderEnumContent) Form(ctx *http.Context) error

Form defined Header `???: application/x-www-form-urlencoded`

func (HeaderEnumContent) HTML

func (h HeaderEnumContent) HTML(ctx *http.Context) error

HTML defined Header `???: text/html`

func (HeaderEnumContent) Is

func (h HeaderEnumContent) Is(value string) http.Arrow

Matches value of HTTP header

func (HeaderEnumContent) JSON

func (h HeaderEnumContent) JSON(ctx *http.Context) error

JSON defines header `???: application/json`

func (HeaderEnumContent) Text

func (h HeaderEnumContent) Text(ctx *http.Context) error

Text defined Header `???: text/plain`

func (HeaderEnumContent) TextHTML

func (h HeaderEnumContent) TextHTML(ctx *http.Context) error

TextHTML defined Header `???: text/html`

func (HeaderEnumContent) TextPlain

func (h HeaderEnumContent) TextPlain(ctx *http.Context) error

TextPlain defined Header `???: text/plain`

func (HeaderEnumContent) To

func (h HeaderEnumContent) To(value *string) http.Arrow

Matches value of HTTP header

type HeaderEnumTransferEncoding

type HeaderEnumTransferEncoding string

Type of HTTP Header, Transfer-Encoding enumeration

const TransferEncoding = HeaderEnumTransferEncoding("Transfer-Encoding")
ƒ.TransferEncoding.Chunked

func (HeaderEnumTransferEncoding) Any

Matches header to any value

func (HeaderEnumTransferEncoding) Chunked

func (h HeaderEnumTransferEncoding) Chunked(ctx *http.Context) error

Chunked defines header `Transfer-Encoding: chunked`

func (HeaderEnumTransferEncoding) Identity

func (h HeaderEnumTransferEncoding) Identity(ctx *http.Context) error

Identity defines header `Transfer-Encoding: identity`

func (HeaderEnumTransferEncoding) Is

Matches value of HTTP header

func (HeaderEnumTransferEncoding) To

Matches value of HTTP header

type HeaderOf

type HeaderOf[T http.ReadableHeaderValues] string

Header matches presence of header in the response or match its entire content. The execution fails with BadMatchHead if the matched value do not meet expectations.

  http.Join(
		...
		ƒ.ContentType.JSON,
		ƒ.ContentEncoding.Is(...),
	)

func (HeaderOf[T]) Any

func (h HeaderOf[T]) Any(ctx *http.Context) error

Matches header to any value

func (HeaderOf[T]) Is

func (h HeaderOf[T]) Is(value T) http.Arrow

Matches value of HTTP header

func (HeaderOf[T]) To

func (h HeaderOf[T]) To(value *T) http.Arrow

Lifts value of HTTP header to variable. It fails if header do not exists

type StatusCode

type StatusCode int

StatusCode is a warpper type over http.StatusCode

http.Join(
	...
	ƒ.Code(http.StatusOK),
)

so that response code is matched using constant

http.Join(
	...
	ƒ.Status.OK,
)

func (StatusCode) Accepted

func (code StatusCode) Accepted(cat *http.Context) error

Accepted ⟼ http.StatusAccepted

func (StatusCode) BadGateway

func (code StatusCode) BadGateway(cat *http.Context) error

BadGateway ⟼ http.StatusBadGateway

func (StatusCode) BadRequest

func (code StatusCode) BadRequest(cat *http.Context) error

BadRequest ⟼ http.StatusBadRequest

func (StatusCode) Conflict

func (code StatusCode) Conflict(cat *http.Context) error

Conflict ⟼ http.StatusConflict

func (StatusCode) Created

func (code StatusCode) Created(cat *http.Context) error

Created ⟼ http.StatusCreated

func (StatusCode) Forbidden

func (code StatusCode) Forbidden(cat *http.Context) error

Forbidden ⟼ http.StatusForbidden

func (StatusCode) Found

func (code StatusCode) Found(cat *http.Context) error

Found ⟼ http.StatusFound

func (StatusCode) GatewayTimeout

func (code StatusCode) GatewayTimeout(cat *http.Context) error

GatewayTimeout ⟼ http.StatusGatewayTimeout

func (StatusCode) Gone

func (code StatusCode) Gone(cat *http.Context) error

Gone ⟼ http.StatusGone

func (StatusCode) HTTPVersionNotSupported

func (code StatusCode) HTTPVersionNotSupported(cat *http.Context) error

HTTPVersionNotSupported ⟼ http.StatusHTTPVersionNotSupported

func (StatusCode) InternalServerError

func (code StatusCode) InternalServerError(cat *http.Context) error

InternalServerError ⟼ http.StatusInternalServerError

func (StatusCode) LengthRequired

func (code StatusCode) LengthRequired(cat *http.Context) error

LengthRequired ⟼ http.StatusLengthRequired

func (StatusCode) MethodNotAllowed

func (code StatusCode) MethodNotAllowed(cat *http.Context) error

MethodNotAllowed ⟼ http.StatusMethodNotAllowed

func (StatusCode) MovedPermanently

func (code StatusCode) MovedPermanently(cat *http.Context) error

MovedPermanently ⟼ http.StatusMovedPermanently

func (StatusCode) MultipleChoices

func (code StatusCode) MultipleChoices(cat *http.Context) error

MultipleChoices ⟼ http.StatusMultipleChoices

func (StatusCode) NoContent

func (code StatusCode) NoContent(cat *http.Context) error

NoContent ⟼ http.StatusNoContent

func (StatusCode) NonAuthoritativeInfo

func (code StatusCode) NonAuthoritativeInfo(cat *http.Context) error

NonAuthoritativeInfo ⟼ http.StatusNonAuthoritativeInfo

func (StatusCode) NotAcceptable

func (code StatusCode) NotAcceptable(cat *http.Context) error

NotAcceptable ⟼ http.StatusNotAcceptable

func (StatusCode) NotFound

func (code StatusCode) NotFound(cat *http.Context) error

NotFound ⟼ http.StatusNotFound

func (StatusCode) NotImplemented

func (code StatusCode) NotImplemented(cat *http.Context) error

NotImplemented ⟼ http.StatusNotImplemented

func (StatusCode) NotModified

func (code StatusCode) NotModified(cat *http.Context) error

NotModified ⟼ http.StatusNotModified

func (StatusCode) OK

func (code StatusCode) OK(cat *http.Context) error

OK ⟼ http.StatusOK

func (StatusCode) PaymentRequired

func (code StatusCode) PaymentRequired(cat *http.Context) error

PaymentRequired ⟼ http.StatusPaymentRequired

func (StatusCode) PreconditionFailed

func (code StatusCode) PreconditionFailed(cat *http.Context) error

PreconditionFailed ⟼ http.StatusPreconditionFailed

func (StatusCode) ProxyAuthRequired

func (code StatusCode) ProxyAuthRequired(cat *http.Context) error

ProxyAuthRequired ⟼ http.StatusProxyAuthRequired

func (StatusCode) RequestEntityTooLarge

func (code StatusCode) RequestEntityTooLarge(cat *http.Context) error

RequestEntityTooLarge ⟼ http.StatusRequestEntityTooLarge

func (StatusCode) RequestTimeout

func (code StatusCode) RequestTimeout(cat *http.Context) error

RequestTimeout ⟼ http.StatusRequestTimeout

func (StatusCode) RequestURITooLong

func (code StatusCode) RequestURITooLong(cat *http.Context) error

RequestURITooLong ⟼ http.StatusRequestURITooLong

func (StatusCode) ResetContent

func (code StatusCode) ResetContent(cat *http.Context) error

ResetContent ⟼ http.StatusResetContent

func (StatusCode) SeeOther

func (code StatusCode) SeeOther(cat *http.Context) error

SeeOther ⟼ http.StatusSeeOther

func (StatusCode) ServiceUnavailable

func (code StatusCode) ServiceUnavailable(cat *http.Context) error

ServiceUnavailable ⟼ http.StatusServiceUnavailable

func (StatusCode) Unauthorized

func (code StatusCode) Unauthorized(cat *http.Context) error

Unauthorized ⟼ http.StatusUnauthorized

func (StatusCode) UnsupportedMediaType

func (code StatusCode) UnsupportedMediaType(cat *http.Context) error

UnsupportedMediaType ⟼ http.StatusUnsupportedMediaType

func (StatusCode) UseProxy

func (code StatusCode) UseProxy(cat *http.Context) error

UseProxy ⟼ http.StatusUseProxy

Jump to

Keyboard shortcuts

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