Documentation ¶
Index ¶
- Constants
- Variables
- type BaseMiddleware
- type CORSMiddleware
- type HTMLPanicFormatter
- type IConfigurationMiddleware
- type JwtMiddleware
- type JwtRequest
- type Logger
- type LoggerInfo
- type Middleware
- type MiddlewareHandler
- type MiddlewareHandlerFunc
- type NextFunc
- type PanicFormatter
- type PanicInformation
- type Recovery
- type RequestTrackerMiddleware
- type RouterMiddleware
- type SessionConfig
- type SessionMiddleware
- type Static
- type StaticOption
- type TextPanicFormatter
Constants ¶
const (
// NoPrintStackBodyString is the body content returned when HTTP stack printing is suppressed
NoPrintStackBodyString = "500 pkg Server Error"
)
Variables ¶
var LoggerDefaultDateFormat = "2006/01/02 - 15:04:05.00"
var LoggerDefaultFormat = "{{.StartTime}} | {{.Status}} \t {{.Duration}} | {{.HostName}} | {{.Method}} | {{.Path}} "
Functions ¶
This section is empty.
Types ¶
type BaseMiddleware ¶
type BaseMiddleware struct {
// contains filtered or unexported fields
}
func (*BaseMiddleware) SetConfiguration ¶
func (mdw *BaseMiddleware) SetConfiguration(config abstractions.IConfiguration)
type CORSMiddleware ¶
type CORSMiddleware struct { *BaseMiddleware Enable bool // contains filtered or unexported fields }
func NewCORS ¶
func NewCORS() *CORSMiddleware
func (*CORSMiddleware) Inovke ¶
func (corsmw *CORSMiddleware) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
func (*CORSMiddleware) SetConfiguration ¶
func (corsmw *CORSMiddleware) SetConfiguration(config abstractions.IConfiguration)
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 IConfigurationMiddleware ¶
type IConfigurationMiddleware interface {
SetConfiguration(config abstractions.IConfiguration)
}
type JwtMiddleware ¶
type JwtMiddleware struct { *BaseMiddleware Enable bool SecretKey string Prefix string Header string SkipPath []interface{} }
func NewJwt ¶
func NewJwt() *JwtMiddleware
func (*JwtMiddleware) Inovke ¶
func (jwtmdw *JwtMiddleware) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
func (*JwtMiddleware) SetConfiguration ¶
func (jwtmdw *JwtMiddleware) SetConfiguration(config abstractions.IConfiguration)
type JwtRequest ¶
type Logger ¶
func (*Logger) Inovke ¶
func (l *Logger) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
func (*Logger) SetDateFormat ¶
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 Middleware ¶ added in v1.6.2
type Middleware struct {
// contains filtered or unexported fields
}
func Build ¶ added in v1.6.2
func Build(handlers []MiddlewareHandler) Middleware
func (Middleware) Invoke ¶ added in v1.6.2
func (m Middleware) Invoke(ctx *context.HttpContext)
type MiddlewareHandler ¶ added in v1.6.2
type MiddlewareHandler interface {
Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
}
func Wrap ¶ added in v1.6.2
func Wrap(handler http.Handler) MiddlewareHandler
func WrapFunc ¶ added in v1.6.2
func WrapFunc(handlerFunc http.HandlerFunc) MiddlewareHandler
type MiddlewareHandlerFunc ¶ added in v1.6.2
type MiddlewareHandlerFunc func(ctx *context.HttpContext, next func(ctx *context.HttpContext))
func (MiddlewareHandlerFunc) Inovke ¶ added in v1.6.2
func (h MiddlewareHandlerFunc) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
type NextFunc ¶ added in v1.6.2
type NextFunc func(ctx *context.HttpContext)
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 ¶
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 xlog.ILogger PrintStack bool LogStack bool PanicHandlerFunc func(*PanicInformation) StackAll bool StackSize int Formatter PanicFormatter }
func (*Recovery) Inovke ¶
func (rec *Recovery) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
type RequestTrackerMiddleware ¶
type RequestTrackerMiddleware struct { *BaseMiddleware // contains filtered or unexported fields }
func NewRequestTracker ¶
func NewRequestTracker() *RequestTrackerMiddleware
func (*RequestTrackerMiddleware) Inovke ¶
func (router *RequestTrackerMiddleware) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
func (*RequestTrackerMiddleware) SetConfiguration ¶
func (router *RequestTrackerMiddleware) SetConfiguration(config abstractions.IConfiguration)
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 SessionConfig ¶ added in v1.6.2
type SessionMiddleware ¶ added in v1.6.2
type SessionMiddleware struct { *BaseMiddleware // contains filtered or unexported fields }
func NewSessionWith ¶ added in v1.6.2
func NewSessionWith(provider identity.IProvider, store store.ISessionStore, config abstractions.IConfiguration) *SessionMiddleware
func (*SessionMiddleware) Inovke ¶ added in v1.6.2
func (sessionMid *SessionMiddleware) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
type Static ¶
type Static struct {
Option *StaticOption
}
func NewStaticWithConfig ¶
func NewStaticWithConfig(configuration abstractions.IConfiguration) *Static
func (*Static) Inovke ¶
func (s *Static) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext))
type StaticOption ¶
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)