Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorMiddleware ¶
func ErrorMiddleware(opts ...Option) gin.HandlerFunc
Returns a gin middleware which writes a response with the error in the context.
func HandlerWithErrorWrapper ¶
func HandlerWithErrorWrapper(h HandlerWithError) gin.HandlerFunc
Allows you to actually use a HandlerWithError as a gin.HandlerFunc. If an error is returned, it adds it to the context with c.Error(err). This needs to be handled with a middleware, such as ErrorMiddleware
Usage:
c.GET("/user", HandlerWithErrorWrapper(UserHandler))
Types ¶
type HandlerWithError ¶
This is essentially the same as gin.HandlerFunc, but allows returning an error. This allows for the more idiomatic use:
func UserHandler (c *gin.Context) error { user, err := db.GetUser(c.Get("user")) if err != nil { return err } c.JSON(200, user) }
type LoggerFunc ¶
type LoggerFunc func(*gin.Context, rErrors.ResponsableError)
A function which should be used to log the responded error.
type Option ¶
type Option func(config) config
An option that customizes the behavior of ErrorMiddleware
func WithDefaultTransformer ¶
func WithDefaultTransformer() Option
Provides an Option which adds the default Transformer to the ErrorMiddleware
This Transformer handles a gin.Error.
func WithLogger ¶
func WithLogger(logger LoggerFunc) Option
Provides an Option which adds the specified LoggerFunc to the ErrorMiddleware
Multiple LoggerFunc may be added.
func WithTransformer ¶
func WithTransformer(tr Transformer) Option
Provides an Option which adds the specified Transformer to the ErrorMiddleware
Multiple Transformer may (and probably should) be added.
type Transformer ¶
type Transformer func(error) rErrors.ResponsableError
A function which should potentially return a rErrors.ResponsableError which wraps the provided error.