request

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxRequestProtocolKey ctxInfo = iota
	CtxRequestMethodKey
	CtxRequestPathKey
)
View Source
const (
	URLQueryPageParam  = "page"
	URLQueryLimitParam = "limit"
	URLQueryOrderParam = "order"
)
View Source
const CtxRequestIDKey = ctxID(iota)

Variables

This section is empty.

Functions

func ID added in v0.0.4

func ID(h http.Handler) http.Handler

ID is a server level middleware. It is called on every request to handle `X-Request-ID` header. If the header already exists in the request, nothing else is done otherwise a new UUID V4 format is generated and added to request `context`.

func IDFromContext added in v0.0.20

func IDFromContext(r *http.Request) string

IDFromContext retrieves the `X-Request-ID` from the current request `context`.

func Info added in v0.0.4

func Info(h http.Handler) http.Handler

Info is a server level middleware. It is called on every request to construct request protocol, method and path values then added to request `context`.

func MethodFromContext added in v0.0.20

func MethodFromContext(r *http.Request) string

MethodFromContext retrieves the request method from the current request `context`.

func PathFromContext added in v0.0.20

func PathFromContext(r *http.Request) string

PathFromContext retrieves the request path from the current request `context`.

func ProtocolFromContext added in v0.0.20

func ProtocolFromContext(r *http.Request) string

ProtocolFromContext retrieves the request protocol from the current request `context`.

func ValidateURLQueryLimitParam added in v0.0.21

func ValidateURLQueryLimitParam(v string, maxLimit int) (int, bool)

ValidateURLQueryLimitParam converts incoming `limit` parameter (v) to a valid `int` type. If the value is empty, `10` is returned as default.

func ValidateURLQueryOrderParam added in v0.0.21

func ValidateURLQueryOrderParam(v string, allowed map[string]string) (map[int]string, bool)

ValidateURLQueryOrderParam extracts comma separated fields from the `order` parameter (v), iterates and compares them against the allowed set of fields (allowed). Empty `order` parameter is considered as a valid input. Any empty field, duplicated field and non-matching field are all considered as an invalid input.

func ValidateURLQueryPageParam added in v0.0.21

func ValidateURLQueryPageParam(v string) (int, bool)

ValidateURLQueryPageParam converts incoming `page` parameter (v) to a valid `int` type. If the value is empty, `1` is returned as default.

Types

This section is empty.

Jump to

Keyboard shortcuts

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