Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
Handler is a generic handler type.
func NewHandler ¶
func NewHandler[In any, Out any]( reqMapper RequestMapper[In], resMapper ResponseMapper[Out], svcFunc ServiceFunc[In, Out], vld Validator, ) Handler[In, Out]
NewHandler creates new handler.
func (Handler[In, Out]) Handle ¶
Handle handles the http request. No need to write a separate handler for each endpoint. Just create request and response mappers and use this generic handler. It will map the request, validate it, call the service function and map the response. It will return an error if any of the steps fail. Assumes that the service function receives context and input type, and returns a output object and an error.
type HandlerFunc ¶
HandlerFunc is API generic handler func type.
type RequestMapper ¶
RequestMapper is generic interfaces for mapping request objects.
type ResponseMapper ¶
type ResponseMapper[Out any] interface { Map(http.ResponseWriter, Out) error }
ResponseMapper is generic interfaces for mapping response objects.
type Router ¶
type Router struct { chi.Router // contains filtered or unexported fields }
Router is the main API router. It is a wrapper around chi.Router with some additional functionality. Chi router can be replaced with any other router that implements net/http.
func (*Router) HttpHandlerFunc ¶
func (r *Router) HttpHandlerFunc(h HandlerFunc[any, any]) http.HandlerFunc
HttpHandlerFunc creates http.HandlerFunc from custom HandlerFunc. It handles API errors and returns them as HTTP errors.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
type ServiceFunc ¶
ServiceFunc is a generic service function type called in a handler.