Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFromRequest ¶
func AssertFromRequest[T FromRequest[T]]() T
AssertFromRequest asserts that the FromRequest interface is correctly implemented for the given type T.
You can use it as a compile time check with a static variable or in an init function:
// static variable var _ = AssertFromRequest[JSON[any]]() func init() { AssertFromRequest[JSON[any]]() }
func Extract ¶
Extract extracts a value of type T from the http.Request. T must either implement the FromRequest interface, or have an Extractor registered using the Register function.
TODO document error, maybe panic
func Handler ¶
Handler adapts a gum handler into an http.Handler. If for any of the handlers parameters cannot be provided by any registered Extractor, nor it implements FromRequest, a panic is raised immediately.
The provided handler function must have either
- no return type
- a single error value
- a single value that implements http.Handler
- a value that implements http.Handler and an error value
Types ¶
type Extractor ¶
Extractor extracts a T from a request. This should be used for non generic types. Implement FromRequest for type T if T itself is generic.
type FromRequest ¶
type FromRequest[T any] interface { // FromRequest creates a new instance of T. // // It should be seen as a static method and only be implemented // on the type T itself, e.g. for a type Foo: // // func (Foo) FromRequest(*http.Request) (Foo, error) { // return "foo", nil // } FromRequest(r *http.Request) (T, error) }
FromRequest defines a method that extracts a T from a http.Request. See FromRequest.FromRequest for more details. I would like to Type it as FromRequest[T FromRequest[T]], but that is not possible as of the time of writing.