http

package
v0.0.0-...-1259547 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

View Source
const (
	//
	StatusContinue           = StatusCode(http.StatusContinue)
	StatusSwitchingProtocols = StatusCode(http.StatusSwitchingProtocols)
	StatusProcessing         = StatusCode(http.StatusProcessing)
	StatusEarlyHints         = StatusCode(http.StatusEarlyHints)

	//
	StatusOK                   = StatusCode(http.StatusOK)
	StatusCreated              = StatusCode(http.StatusCreated)
	StatusAccepted             = StatusCode(http.StatusAccepted)
	StatusNonAuthoritativeInfo = StatusCode(http.StatusNonAuthoritativeInfo)
	StatusNoContent            = StatusCode(http.StatusNoContent)
	StatusResetContent         = StatusCode(http.StatusResetContent)
	StatusPartialContent       = StatusCode(http.StatusPartialContent)
	StatusMultiStatus          = StatusCode(http.StatusMultiStatus)
	StatusAlreadyReported      = StatusCode(http.StatusAlreadyReported)
	StatusIMUsed               = StatusCode(http.StatusIMUsed)

	//
	StatusMultipleChoices   = StatusCode(http.StatusMultipleChoices)
	StatusMovedPermanently  = StatusCode(http.StatusMovedPermanently)
	StatusFound             = StatusCode(http.StatusFound)
	StatusSeeOther          = StatusCode(http.StatusSeeOther)
	StatusNotModified       = StatusCode(http.StatusNotModified)
	StatusUseProxy          = StatusCode(http.StatusUseProxy)
	StatusTemporaryRedirect = StatusCode(http.StatusTemporaryRedirect)
	StatusPermanentRedirect = StatusCode(http.StatusPermanentRedirect)

	//
	StatusBadRequest                   = StatusCode(http.StatusBadRequest)
	StatusUnauthorized                 = StatusCode(http.StatusUnauthorized)
	StatusPaymentRequired              = StatusCode(http.StatusPaymentRequired)
	StatusForbidden                    = StatusCode(http.StatusForbidden)
	StatusNotFound                     = StatusCode(http.StatusNotFound)
	StatusMethodNotAllowed             = StatusCode(http.StatusMethodNotAllowed)
	StatusNotAcceptable                = StatusCode(http.StatusNotAcceptable)
	StatusProxyAuthRequired            = StatusCode(http.StatusProxyAuthRequired)
	StatusRequestTimeout               = StatusCode(http.StatusRequestTimeout)
	StatusConflict                     = StatusCode(http.StatusConflict)
	StatusGone                         = StatusCode(http.StatusGone)
	StatusLengthRequired               = StatusCode(http.StatusLengthRequired)
	StatusPreconditionFailed           = StatusCode(http.StatusPreconditionFailed)
	StatusRequestEntityTooLarge        = StatusCode(http.StatusRequestEntityTooLarge)
	StatusRequestURITooLong            = StatusCode(http.StatusRequestURITooLong)
	StatusUnsupportedMediaType         = StatusCode(http.StatusUnsupportedMediaType)
	StatusRequestedRangeNotSatisfiable = StatusCode(http.StatusRequestedRangeNotSatisfiable)
	StatusExpectationFailed            = StatusCode(http.StatusExpectationFailed)
	StatusTeapot                       = StatusCode(http.StatusTeapot)
	StatusMisdirectedRequest           = StatusCode(http.StatusMisdirectedRequest)
	StatusUnprocessableEntity          = StatusCode(http.StatusUnprocessableEntity)
	StatusLocked                       = StatusCode(http.StatusLocked)
	StatusFailedDependency             = StatusCode(http.StatusFailedDependency)
	StatusTooEarly                     = StatusCode(http.StatusTooEarly)
	StatusUpgradeRequired              = StatusCode(http.StatusUpgradeRequired)
	StatusPreconditionRequired         = StatusCode(http.StatusPreconditionRequired)
	StatusTooManyRequests              = StatusCode(http.StatusTooManyRequests)
	StatusRequestHeaderFieldsTooLarge  = StatusCode(http.StatusRequestHeaderFieldsTooLarge)
	StatusUnavailableForLegalReasons   = StatusCode(http.StatusUnavailableForLegalReasons)

	//
	StatusInternalServerError           = StatusCode(http.StatusInternalServerError)
	StatusNotImplemented                = StatusCode(http.StatusNotImplemented)
	StatusBadGateway                    = StatusCode(http.StatusBadGateway)
	StatusServiceUnavailable            = StatusCode(http.StatusServiceUnavailable)
	StatusGatewayTimeout                = StatusCode(http.StatusGatewayTimeout)
	StatusHTTPVersionNotSupported       = StatusCode(http.StatusHTTPVersionNotSupported)
	StatusVariantAlsoNegotiates         = StatusCode(http.StatusVariantAlsoNegotiates)
	StatusInsufficientStorage           = StatusCode(http.StatusInsufficientStorage)
	StatusLoopDetected                  = StatusCode(http.StatusLoopDetected)
	StatusNotExtended                   = StatusCode(http.StatusNotExtended)
	StatusNetworkAuthenticationRequired = StatusCode(http.StatusNetworkAuthenticationRequired)
)

Variables

This section is empty.

Functions

func Default

func Default() assay.Config

Default configures default HTTP stack for the category.

func DefaultIO

func DefaultIO(opts ...assay.Config) *assay.IOCat

DefaultIO creates default HTTP IO category use for development only

func Join

func Join(arrows ...Arrow) assay.Arrow

Join composes HTTP arrows to high-order function (a ⟼ b, b ⟼ c, c ⟼ d) ⤇ a ⟼ d

func Stack

func Stack(client *http.Client) assay.Config

Stack configures custom HTTP stack for the category.

Types

type Arrow

type Arrow func(*assay.IOCat) *assay.IOCat

Arrow is a morphism applied to HTTP

type StatusCode

type StatusCode int

StatusCode is a base type for typesafe HTTP status codes. The library advertises a usage of "pattern-matching" on HTTP status handling, which helps developers to catch mismatch of HTTP statuses along with other side-effect failures.

The final values of HTTP statuses embeds StatusCode type. It makes them to look like a "sum-types" and be compatible with any other error (side effect failures) within IO category. Use final type instances in the error handling routines.

Use type switch for error handling "branches"

switch e := io.Fail.(type) {
case nil:
  // Nothing
case StatusCode:
  switch err {
  case http.StatusOK:
    // HTTP 200 OK
  case http.StatusNotFound:
    // HTTP 404 NotFound
  default:
    // any other HTTP errors
  }
default:
  // any other errors
}

Conditional error handling on expected HTTP Status

if errors.Is(io.Fail, http.StatusNotFound) {
}

Conditional error handling on any HTTP Status

if _, ok := io.Fail.(http.StatusCode); ok {
}

func NewStatusCode

func NewStatusCode(code int, required ...StatusCode) StatusCode

NewStatusCode transforms integer codes to types

func (StatusCode) Error

func (e StatusCode) Error() string

Error makes StatusCode to be error

func (StatusCode) Is

func (e StatusCode) Is(err error) bool

Is compares wrapped errors

func (StatusCode) Required

func (e StatusCode) Required() int

Required returns awaited (expected, required) HTTP status

func (StatusCode) Value

func (e StatusCode) Value() int

Value transforms StatusCode type to integer value: StatusCode ⟼ int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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