ginMerry

package module
v0.0.0-...-ed2bd26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2016 License: MIT Imports: 2 Imported by: 0

README

forthebadge

gin-merry GoDoc

Middleware that marries merry errors and Gin.

It pretty-prints merry errors to the user with all the context embedded in the error.

This middleware is compatible with Golang's Gin HTTP router and merry errors with context™.

After enabling the middleware, if the handler returns an error to the gin.Context, it will be printed to the user with all the additional context that came with the error. The errors' queue is cleared, so the logs won't be cluttered with the useless errors.

However, if the error has code 500 - then the error is considered bad/not merry at all; some default text is printed to the user and the error is passed down the chain for logging.

Documentation

Overview

Package ginMerry provides the middleware for Gin that pretty-prints the merry errors. If the code is 500 - the error is masked and generic output is retuned to user.

Index

Constants

View Source
const DefaultGenericError = `Internal Server Error!`

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	// Debug controls if a call stack should be printed with every error.
	// Defaults to false.
	Debug bool

	// GenericError is a string that is shown on error code 500 or
	// non-merry errors.
	GenericError string

	// LogFunc is the function that gets called each time an error is occurred.
	LogFunc func(err string, code int, vals map[string]interface{})
}

Middleware is a handler container for the middleware.

func New

func New(debug bool) *Middleware

New returns new middleware container with default options. If parameter is true then debug mode is assumed.

func (*Middleware) Handler

func (m *Middleware) Handler() gin.HandlerFunc

Handler returns the middleware func.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL