Documentation ¶
Index ¶
- type Config
- type Handler
- type HandlerFunc
- type Router
- func (router *Router[T]) Handle(pattern string, handler Handler[T])
- func (router *Router[T]) HandleFunc(pattern string, ...)
- func (router *Router[T]) Listen(conf *Config) error
- func (router *Router[T]) NotFoundHandle(handler Handler[T])
- func (router *Router[T]) NotFoundHandleFunc(handler func(http.ResponseWriter, *http.Request, T))
- func (router *Router[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler[T any] interface { ServeHTTP(http.ResponseWriter, *http.Request, T) }
Defining custom interface with ServeHTTP signature containing custom parameter to register custom handlers with DB We need to expect not anymore "http.Handler" but simply Handler
type HandlerFunc ¶
type HandlerFunc[T any] func(http.ResponseWriter, *http.Request, T)
Used to type any function that has this signature into a type that implemets the Handler interface, to allow it to be registerd on the mux with a corresponding pattern. Upon pattern match, this function will be invoked it call the user's defined callback function 'f' with all the arguments passed from the multiplexer adapter middleware (the one that turns the standard http.Handler signature with our custom ServeHTTP with db argument)
func (HandlerFunc[T]) ServeHTTP ¶
func (f HandlerFunc[T]) ServeHTTP(w http.ResponseWriter, r *http.Request, c T)
type Router ¶
type Router[T any] struct { Mux *http.ServeMux Context T // contains filtered or unexported fields }
func (*Router[T]) HandleFunc ¶
func (*Router[T]) NotFoundHandle ¶
Register on our Mux the Handler Type provided in args for "Not Found" It must be a Handler Type, otherwise use 'NotFoundHandleFunc'
func (*Router[T]) NotFoundHandleFunc ¶
func (router *Router[T]) NotFoundHandleFunc(handler func(http.ResponseWriter, *http.Request, T))
Commodity wrapper for registering a custom passed Not Found function calls the 'NotFoundHandle' function, but allow us to pass a custom function that matches the signature.