Middleware

package
v1.4.9 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoPrintStackBodyString is the body content returned when HTTP stack printing is suppressed
	NoPrintStackBodyString = "500 Internal Server Error"
)

Variables

View Source
var LoggerDefaultDateFormat = "2006/01/02 - 15:04:05.00"
View Source
var LoggerDefaultFormat = "{{.StartTime}} | {{.Status}} \t {{.Duration}} | {{.HostName}} | {{.Method}} | {{.Path}} "

Functions

This section is empty.

Types

type ALogger

type ALogger interface {
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

type HTMLPanicFormatter

type HTMLPanicFormatter struct{}

HTMLPanicFormatter output the stack inside an HTML page. This has been largely inspired by https://github.com/go-martini/martini/pull/156/commits.

func (*HTMLPanicFormatter) FormatPanicError

func (t *HTMLPanicFormatter) FormatPanicError(rw http.ResponseWriter, r *http.Request, infos *PanicInformation)

type Logger

type Logger struct {
	ALogger ALogger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *Logger

func (*Logger) Inovke

func (l *Logger) Inovke(ctx *Context.HttpContext, next func(ctx *Context.HttpContext))

func (*Logger) SetDateFormat

func (l *Logger) SetDateFormat(format string)

func (*Logger) SetFormat

func (l *Logger) SetFormat(format string)

type LoggerInfo

type LoggerInfo struct {
	StartTime string
	Status    int
	Duration  string
	HostName  string
	Method    string
	Path      string
	Body      string
	Request   *http.Request
}

func (*LoggerInfo) MethodColor

func (p *LoggerInfo) MethodColor() string

MethodColor is the ANSI color for appropriately logging http method to a terminal.

func (*LoggerInfo) ResetColor

func (p *LoggerInfo) ResetColor() string

ResetColor resets all escape attributes.

func (*LoggerInfo) StatusCodeColor

func (p *LoggerInfo) StatusCodeColor() string

StatusCodeColor is the ANSI color for appropriately logging http status code to a terminal.

type PanicFormatter

type PanicFormatter interface {
	// FormatPanicError output the stack for a given answer/response.
	// In case the the middleware should not output the stack trace,
	// the field `Stack` of the passed `PanicInformation` instance equals `[]byte{}`.
	FormatPanicError(rw http.ResponseWriter, r *http.Request, infos *PanicInformation)
}

PanicFormatter is an interface on object can implement to be able to output the stack trace

type PanicInformation

type PanicInformation struct {
	RecoveredPanic interface{}
	Stack          []byte
	Request        *http.Request
}

PanicInformation contains all elements for printing stack informations.

func (*PanicInformation) RequestDescription

func (p *PanicInformation) RequestDescription() string

RequestDescription returns a printable description of the url

func (*PanicInformation) StackAsString

func (p *PanicInformation) StackAsString() string

StackAsString returns a printable version of the stack

type Recovery

type Recovery struct {
	Logger           ALogger
	PrintStack       bool
	LogStack         bool
	PanicHandlerFunc func(*PanicInformation)
	StackAll         bool
	StackSize        int
	Formatter        PanicFormatter
}

func NewRecovery

func NewRecovery() *Recovery

NewRecovery returns a new instance of Recovery

func (*Recovery) Inovke

func (rec *Recovery) Inovke(ctx *Context.HttpContext, next func(ctx *Context.HttpContext))

type RouterMiddleware

type RouterMiddleware struct {
	RouterBuilder Router.IRouterBuilder
}

func NewRouter

func NewRouter(builder Router.IRouterBuilder) *RouterMiddleware

func (*RouterMiddleware) Inovke

func (router *RouterMiddleware) Inovke(ctx *Context.HttpContext, next func(ctx *Context.HttpContext))

type Static

type Static struct {
	IsPrefix   bool
	VirualPath string
}

func NewStatic

func NewStatic(path string) *Static

func (*Static) Inovke

func (s *Static) Inovke(ctx *Context.HttpContext, next func(ctx *Context.HttpContext))

func (*Static) SetPrefix

func (s *Static) SetPrefix()

type TextPanicFormatter

type TextPanicFormatter struct{}

TextPanicFormatter output the stack as simple text on os.Stdout. If no `Content-Type` is set, it will output the data as `text/plain; charset=utf-8`. Otherwise, the origin `Content-Type` is kept.

func (*TextPanicFormatter) FormatPanicError

func (t *TextPanicFormatter) FormatPanicError(rw http.ResponseWriter, r *http.Request, infos *PanicInformation)

Jump to

Keyboard shortcuts

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