Help us shape the future of Go! Take the 2026 Go Developer Survey

http

package
v1.0.76 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderContentType = "Content-Type"
)

Variables

View Source
var (
	Response = T.First[*H.Response, []byte]
	Body     = T.Second[*H.Response, []byte]
)
View Source
var (

	// ValidateResponse validates an HTTP response and returns an [E.Either] if the response is not a success
	ValidateResponse = E.FromPredicate(isValidStatus, StatusCodeError)

	// ValidateJsonResponse checks if an HTTP response is a valid JSON response
	ValidateJsonResponse = F.Flow2(
		E.Of[error, *H.Response],
		E.ChainFirst(F.Flow5(
			GetHeader,
			R.Lookup[H.Header](HeaderContentType),
			O.Chain(A.First[string]),
			E.FromOption[string](errors.OnNone("unable to access the [%s] header", HeaderContentType)),
			E.ChainFirst(validateJsonContentTypeString),
		)))
)

Functions

func GetBody

func GetBody(resp *H.Response) io.ReadCloser

func GetHeader

func GetHeader(resp *H.Response) H.Header

func ParseMediaType

func ParseMediaType(mediaType string) E.Either[error, ParsedMediaType]

ParseMediaType parses a media type into a tuple

func StatusCodeError

func StatusCodeError(resp *H.Response) error

Types

type FullResponse

type FullResponse = T.Tuple2[*H.Response, []byte]

FullResponse represents a full http response, including headers and body

type ParsedMediaType

type ParsedMediaType = T.Tuple2[string, map[string]string]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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