Documentation
¶
Index ¶
- Variables
- func HTTPRouterWrapHandler(h http.Handler) httprouter.Handle
- func IsUnMarshalError(err error) bool
- func JSONContentTypeMiddleware(next http.Handler) http.Handler
- func MarshalJSON(v interface{}) ([]byte, error)
- func PanicRecoverMiddleware(next http.Handler) http.Handler
- func UnMarshalJSON(data []byte, v interface{}) error
- type Body
- type ErrorHandler
- type ErrorMessage
- type HTTPMethod
- type Handler
- type HandlerFunc
- type Middleware
- type MiddlewareManager
- type MiddlewareMapper
- type MiddlewaresMap
- type Request
- type Response
- func (r Response) Bytes() []byte
- func (r Response) ContentType() string
- func (r Response) JSON(v interface{}) (Response, error)
- func (r Response) NoContent() (Response, error)
- func (r Response) NotFound() (Response, error)
- func (r Response) Ok(bytes []byte) (Response, error)
- func (r Response) ServerError(err error) (Response, error)
- func (r *Response) SetBytes(b []byte)
- func (r *Response) SetContentType(s string)
- func (r *Response) SetStatus(s int)
- func (r Response) Status() int
- func (r Response) Writer() http.ResponseWriter
- type Route
- type RouteParams
- type Router
- func (r *Router) AddRoutes(g string, newRoutes ...*Route)
- func (r *Router) DELETE(token string, path string, h Handler) *Route
- func (r *Router) GET(token string, path string, h Handler) *Route
- func (r *Router) HEAD(token string, path string, h Handler) *Route
- func (r *Router) OPTIONS(token string, path string, h Handler) *Route
- func (r *Router) PATCH(token string, path string, h Handler) *Route
- func (r *Router) POST(token string, path string, h Handler) *Route
- func (r *Router) PUT(token string, path string, h Handler) *Route
- func (r *Router) SetErrorHandler(e ErrorHandler)
- func (r *Router) SetMiddlewares(m []Middleware)
- func (r *Router) SetMiddlewaresMap(m MiddlewaresMap)
- func (r *Router) Start() *Router
- type Routes
- type UnMarshalError
Constants ¶
This section is empty.
Variables ¶
var SupressError bool
SupressError sets if http error should be sent
Functions ¶
func HTTPRouterWrapHandler ¶
func HTTPRouterWrapHandler(h http.Handler) httprouter.Handle
HTTPRouterWrapHandler wraps the http.Handler with a httprouter.Handle The httprouter.Handle supports better parse of URL params
func IsUnMarshalError ¶
IsUnMarshalError verifies if error is an UnMarshalError
func JSONContentTypeMiddleware ¶
JSONContentTypeMiddleware forces application/json Content-Type
func MarshalJSON ¶
MarshalJSON returns the JSON encoding of v
func PanicRecoverMiddleware ¶
PanicRecoverMiddleware recovers a panic error
func UnMarshalJSON ¶
UnMarshalJSON parses the JSON-encoded data and stores in v interface
Types ¶
type Body ¶
type Body struct {
// contains filtered or unexported fields
}
Body represents the request body
func (Body) UnMarshalJSON ¶
UnMarshalJSON parses the JSON into the body
type ErrorHandler ¶
type ErrorHandler func(HandlerFunc) HandlerFunc
ErrorHandler represents the global error handler
type ErrorMessage ¶
type ErrorMessage struct {
Message []string `json:"errors"`
}
ErrorMessage represents errors sent as response
func NewErrorMessage ¶
func NewErrorMessage(message ...string) ErrorMessage
NewErrorMessage creates a ErrorMessages instance
type HTTPMethod ¶
type HTTPMethod func(string, httprouter.Handle)
HTTPMethod represents a http method
type HandlerFunc ¶
HandlerFunc represents the routes created from a function
type Middleware ¶
type Middleware struct { Token string Constructor alice.Constructor Silent bool }
Middleware represents a middleware
type MiddlewareManager ¶
type MiddlewareManager struct {
Middlewares []Middleware
}
MiddlewareManager represents the middleware manager. It can stores built-in middlewares or external middlewares. The middlewares are supported via alice package.
func NewMiddlewareManager ¶
func NewMiddlewareManager() *MiddlewareManager
NewMiddlewareManager creates an instance of MiddlewareManager
func (*MiddlewareManager) Add ¶
func (m *MiddlewareManager) Add(token string, constructor alice.Constructor)
Add adds a middleware to the middlewares chain
func (*MiddlewareManager) AddSilent ¶
func (m *MiddlewareManager) AddSilent(token string, constructor alice.Constructor)
AddSilent adds a silent middleware to the middlewares chain
type MiddlewareMapper ¶
type MiddlewareMapper struct {
MiddlewaresMap MiddlewaresMap
}
MiddlewareMapper represents the mapper of middlewares and routes
func NewMiddlewareMapper ¶
func NewMiddlewareMapper() *MiddlewareMapper
NewMiddlewareMapper creates an instance of NewMiddlewareMapper
func (*MiddlewareMapper) Map ¶
func (mapper *MiddlewareMapper) Map(routeToken string, middlewareTokens ...string)
Map maps middlewares for routes. A route can have specifics middlewares and not to use the globals.
type MiddlewaresMap ¶
MiddlewaresMap represents the middlewares map.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents the server request
func NewRequest ¶
NewRequest creates an instance of Request
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response represents the server response
func BadRequest ¶
BadRequest creates a BadRequest response
func NewResponse ¶
func NewResponse(w http.ResponseWriter) Response
NewResponse creates an instance of Response
func (Response) ContentType ¶
ContentType gets the response content type
func (Response) ServerError ¶
ServerError creates an InternalServerError response
func (*Response) SetContentType ¶
SetContentType sets the response content type
func (Response) Writer ¶
func (r Response) Writer() http.ResponseWriter
Writer gets the http response writer
type Route ¶
type Route struct { Token string Method HTTPMethod Path string Handler HandlerFunc }
Route represents a route
func NewRoute ¶
func NewRoute(token string, method HTTPMethod, path string, handler Handler) *Route
NewRoute creates an instance of *Route using a struct
func NewRouteFunc ¶
func NewRouteFunc(token string, method HTTPMethod, path string, handler HandlerFunc) *Route
NewRouteFunc creates an instance of *Route using a func
type RouteParams ¶
type RouteParams struct {
Params httprouter.Params
}
RouteParams represents the params for a route
func (RouteParams) AsInt ¶
func (p RouteParams) AsInt(name string) int
AsInt gets the param as an Int
func (RouteParams) AsString ¶
func (p RouteParams) AsString(name string) string
AsString gets the param as an String
type Router ¶
type Router struct { *httprouter.Router // contains filtered or unexported fields }
Router represents the router
func (*Router) SetErrorHandler ¶
func (r *Router) SetErrorHandler(e ErrorHandler)
SetErrorHandler defines the error handler for the router
func (*Router) SetMiddlewares ¶
func (r *Router) SetMiddlewares(m []Middleware)
SetMiddlewares defines the middlewares for the router
func (*Router) SetMiddlewaresMap ¶
func (r *Router) SetMiddlewaresMap(m MiddlewaresMap)
SetMiddlewaresMap defines the middlewares map fot the router
func (*Router) Start ¶
Start configures all necessary steps for each route. The router starts the middlewares chain with the context.ClearHandler. It is responsible to clear all data in the request context. After, it configures specific middlewares for a route or adds all. So, the router adds the error handle as the last handler in the chain.
type UnMarshalError ¶
type UnMarshalError struct {
Msg string
}
UnMarshalError represents an unmarshal error
func NewUnMarshalError ¶
func NewUnMarshalError(msg string) UnMarshalError
NewUnMarshalError an instance of UnMarshalError