httpx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalCookie

func MarshalCookie(val any) (string, error)

MarshalCookie marshals 'val' using JSON, encodes using Base64 and returns.

func ReadJSON

func ReadJSON(r *http.Request, ptr any) error

ReadJSON decodes the body of the request as JSON into 'ptr'.

func Serve

func Serve(ctx context.Context, addr string, r http.Handler, graceT time.Duration) error

Serve serves the given handler on 'addr'. Blocks until server exits due to critical error. On context-cancellation, server will be shutdown gracefully.

func UnmarshalCookie

func UnmarshalCookie(r *http.Request, key string, into any) bool

UnmarshalCookie reads the cookie value as base64 encoded JSON value. Returns true if successful.

func WrapErrH

func WrapErrH(fn func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc

WrapErrH is an extended version of http.HandlerFunc with automatic error handling.

func WriteErr

func WriteErr(w http.ResponseWriter, r *http.Request, err error)

WriteErr writes the error value to the ResponseWriter. HTTP status is inferred from the error value.

func WriteJSON

func WriteJSON(w http.ResponseWriter, r *http.Request, status int, v any)

WriteJSON marshals 'v' as JSON value and writes to the ResponseWriter. No content is written if request-method is HEAD or status is 204.

Types

This section is empty.

Jump to

Keyboard shortcuts

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