Documentation ¶
Index ¶
- Constants
- Variables
- func Accepted(w http.ResponseWriter, msg ...interface{})
- func AddContext(this *http.Request, k interface{}, v interface{}) *http.Request
- func BadGateway(w http.ResponseWriter, msg ...interface{})
- func BadRequest(w http.ResponseWriter, msg ...interface{})
- func Conflict(w http.ResponseWriter, msg ...interface{})
- func Continue(w http.ResponseWriter, msg ...interface{})
- func CreateMiddleWare(f func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler)) func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler)
- func Created(w http.ResponseWriter, msg ...interface{})
- func Error(w http.ResponseWriter, code int)
- func ExpectationFailed(w http.ResponseWriter, msg ...interface{})
- func Forbidden(w http.ResponseWriter, msg ...interface{})
- func Found(w http.ResponseWriter, msg ...interface{})
- func GatewayTimeout(w http.ResponseWriter, msg ...interface{})
- func Gone(w http.ResponseWriter, msg ...interface{})
- func HTTPVersionNotSupported(w http.ResponseWriter, msg ...interface{})
- func InternalServerError(w http.ResponseWriter, msg ...interface{})
- func JSON(w ResponseWriter, val interface{}, code ...int)
- func LengthRequired(w http.ResponseWriter, msg ...interface{})
- func MethodNotAllowed(w http.ResponseWriter, msg ...interface{})
- func MovedPermanently(w http.ResponseWriter, msg ...interface{})
- func MultipleChoices(w http.ResponseWriter, msg ...interface{})
- func NoContent(w http.ResponseWriter, msg ...interface{})
- func NonAuthoritativeInfo(w http.ResponseWriter, msg ...interface{})
- func NotAcceptable(w http.ResponseWriter, msg ...interface{})
- func NotFound(w http.ResponseWriter, msg ...interface{})
- func NotImplemented(w http.ResponseWriter, msg ...interface{})
- func NotModified(w http.ResponseWriter, msg ...interface{})
- func OK(w http.ResponseWriter, msg ...interface{})
- func PartialContent(w http.ResponseWriter, msg ...interface{})
- func PaymentRequired(w http.ResponseWriter, msg ...interface{})
- func PreconditionFailed(w http.ResponseWriter, msg ...interface{})
- func ProxyAuthRequired(w http.ResponseWriter, msg ...interface{})
- func RequestEntityTooLarge(w http.ResponseWriter, msg ...interface{})
- func RequestTimeout(w http.ResponseWriter, msg ...interface{})
- func RequestURITooLong(w http.ResponseWriter, msg ...interface{})
- func RequestedRangeNotSatisfiable(w http.ResponseWriter, msg ...interface{})
- func ResetContent(w http.ResponseWriter, msg ...interface{})
- func SeeOther(w http.ResponseWriter, msg ...interface{})
- func ServiceUnavailable(w http.ResponseWriter, msg ...interface{})
- func SwitchingProtocols(w http.ResponseWriter, msg ...interface{})
- func Teapot(w http.ResponseWriter, msg ...interface{})
- func TemporaryRedirect(w http.ResponseWriter, msg ...interface{})
- func Unauthorized(w http.ResponseWriter, msg ...interface{})
- func UnsupportedMediaType(w http.ResponseWriter, msg ...interface{})
- func UseProxy(w http.ResponseWriter, msg ...interface{})
- func Vars(this *http.Request) map[string]string
- func XML(w ResponseWriter, val interface{}, code ...int)
- type BuildVarsFunc
- type Cors
- type CorsOptions
- type Handler
- type MatcherFunc
- type MiddleWare
- type MiddlewareFunc
- type MiddlewareMatcher
- type PanicFormatter
- type PanicInformation
- type Recovery
- type ResponseWriter
- type Route
- func (this *Route) BuildOnly() *Route
- func (this *Route) BuildVarsFunc(f BuildVarsFunc) *Route
- func (this *Route) GetError() error
- func (this *Route) GetHandler() http.Handler
- func (this *Route) GetHostTemplate() (string, error)
- func (this *Route) GetMethods() ([]string, error)
- func (this *Route) GetName() string
- func (this *Route) GetPathRegexp() (string, error)
- func (this *Route) GetPathTemplate() (string, error)
- func (this *Route) GetQueriesRegexp() ([]string, error)
- func (this *Route) GetQueriesTemplates() ([]string, error)
- func (this *Route) Handler(handler http.Handler) *Route
- func (this *Route) HandlerFunc(f func(http.ResponseWriter, *http.Request)) *Route
- func (this *Route) Headers(pairs ...string) *Route
- func (this *Route) HeadersRegexp(pairs ...string) *Route
- func (this *Route) Host(tpl string) *Route
- func (this *Route) Match(req *http.Request, match *RouteMatch) bool
- func (this *Route) MatcherFunc(f MatcherFunc) *Route
- func (this *Route) Methods(methods ...string) *Route
- func (this *Route) Name(name string) *Route
- func (this *Route) Path(tpl string) *Route
- func (this *Route) PathPrefix(tpl string) *Route
- func (this *Route) Queries(pairs ...string) *Route
- func (this *Route) Schemes(schemes ...string) *Route
- func (this *Route) SkipClean() bool
- func (this *Route) Subrouter() *Router
- func (this *Route) URL(pairs ...string) (*url.URL, error)
- func (this *Route) URLHost(pairs ...string) (*url.URL, error)
- func (this *Route) URLPath(pairs ...string) (*url.URL, error)
- type RouteMatch
- type Router
- func (this *Router) BuildVarsFunc(f BuildVarsFunc) *Route
- func (this *Router) Get(name string) *Route
- func (this *Router) GetRoute(name string) *Route
- func (this *Router) Handle(path string, handler http.Handler) *Route
- func (this *Router) HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *Route
- func (this *Router) Headers(pairs ...string) *Route
- func (this *Router) Host(tpl string) *Route
- func (this *Router) Match(req *http.Request, match *RouteMatch) bool
- func (this *Router) MatcherFunc(f MatcherFunc) *Route
- func (this *Router) Methods(methods ...string) *Route
- func (this *Router) Name(name string) *Route
- func (this *Router) NewRoute() *Route
- func (this *Router) Path(tpl string) *Route
- func (this *Router) PathExcept(p string, mwf ...MiddlewareFunc)
- func (this *Router) PathExcepts(p []string, mwf ...MiddlewareFunc)
- func (this *Router) PathIn(p []string, mwf ...MiddlewareFunc)
- func (this *Router) PathOnly(p string, mwf ...MiddlewareFunc)
- func (this *Router) PathPrefix(tpl string) *Route
- func (this *Router) Queries(pairs ...string) *Route
- func (this *Router) Schemes(schemes ...string) *Route
- func (this *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (this *Router) SkipClean(value bool) *Router
- func (this *Router) StrictSlash(value bool) *Router
- func (this *Router) Use(mwf ...MiddlewareFunc)
- func (this *Router) UseEncodedPath() *Router
- func (this *Router) Walk(walkFn WalkFunc) error
- func (this *Router) When(match MiddlewareMatcher, mwf ...MiddlewareFunc)
- type Static
- type TextPanicFormatter
- type WalkFunc
Constants ¶
const NoPrintStackBodyString = "500 Internal Server Error"
Variables ¶
var ( ErrMethodMismatch = errors.New("method is not allowed") ErrNotFound = errors.New("no matching route was found") )
var ErrHandler = CreateMiddleWare(func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler) { rec := NewRecovery() rec.ServeHTTP(w.(ResponseWriter), r, next) })
var FormParser = CreateMiddleWare(func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler) { err := r.ParseForm() if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusBadRequest) } err = r.ParseMultipartForm(1024) if err != nil && err != http.ErrNotMultipart { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusBadRequest) } if next != nil { next.ServeHTTP(w, r) } })
var Pretty = true
Pretty response formatting.
var RequestLogger = CreateMiddleWare(func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler) { start := time.Now() log.Info("->"+r.Method, zap.String("path", r.Host+r.URL.Path), zap.Any("form", r.Form), zap.Int64("size", r.ContentLength), zap.String("ip", r.RemoteAddr), zap.String("time", util.FormatTimeToString(start))) next.ServeHTTP(w, r) resp := w.(ResponseWriter) log.Info("<-"+r.Method, zap.String("path", r.Host+r.URL.Path), zap.Int("status", resp.Status()), zap.Any("resp", resp.GetResponse()), zap.Int("size", resp.Size()), zap.Int64("ms", time.Since(start).Milliseconds())) })
var SkipRouter = errors.New("skip this router")
Functions ¶
func Accepted ¶
func Accepted(w http.ResponseWriter, msg ...interface{})
func BadGateway ¶
func BadGateway(w http.ResponseWriter, msg ...interface{})
func BadRequest ¶
func BadRequest(w http.ResponseWriter, msg ...interface{})
func Conflict ¶
func Conflict(w http.ResponseWriter, msg ...interface{})
func Continue ¶
func Continue(w http.ResponseWriter, msg ...interface{})
func CreateMiddleWare ¶
func CreateMiddleWare(f func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler)) func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler)
func Created ¶
func Created(w http.ResponseWriter, msg ...interface{})
func Error ¶
func Error(w http.ResponseWriter, code int)
Error responds with a generic status code response.
func ExpectationFailed ¶
func ExpectationFailed(w http.ResponseWriter, msg ...interface{})
func Forbidden ¶
func Forbidden(w http.ResponseWriter, msg ...interface{})
func Found ¶
func Found(w http.ResponseWriter, msg ...interface{})
func GatewayTimeout ¶
func GatewayTimeout(w http.ResponseWriter, msg ...interface{})
func Gone ¶
func Gone(w http.ResponseWriter, msg ...interface{})
func HTTPVersionNotSupported ¶
func HTTPVersionNotSupported(w http.ResponseWriter, msg ...interface{})
func InternalServerError ¶
func InternalServerError(w http.ResponseWriter, msg ...interface{})
func JSON ¶
func JSON(w ResponseWriter, val interface{}, code ...int)
JSON response with optional status code.
func LengthRequired ¶
func LengthRequired(w http.ResponseWriter, msg ...interface{})
func MethodNotAllowed ¶
func MethodNotAllowed(w http.ResponseWriter, msg ...interface{})
func MovedPermanently ¶
func MovedPermanently(w http.ResponseWriter, msg ...interface{})
func MultipleChoices ¶
func MultipleChoices(w http.ResponseWriter, msg ...interface{})
func NoContent ¶
func NoContent(w http.ResponseWriter, msg ...interface{})
func NonAuthoritativeInfo ¶
func NonAuthoritativeInfo(w http.ResponseWriter, msg ...interface{})
func NotAcceptable ¶
func NotAcceptable(w http.ResponseWriter, msg ...interface{})
func NotFound ¶
func NotFound(w http.ResponseWriter, msg ...interface{})
func NotImplemented ¶
func NotImplemented(w http.ResponseWriter, msg ...interface{})
func NotModified ¶
func NotModified(w http.ResponseWriter, msg ...interface{})
func OK ¶
func OK(w http.ResponseWriter, msg ...interface{})
func PartialContent ¶
func PartialContent(w http.ResponseWriter, msg ...interface{})
func PaymentRequired ¶
func PaymentRequired(w http.ResponseWriter, msg ...interface{})
func PreconditionFailed ¶
func PreconditionFailed(w http.ResponseWriter, msg ...interface{})
func ProxyAuthRequired ¶
func ProxyAuthRequired(w http.ResponseWriter, msg ...interface{})
func RequestEntityTooLarge ¶
func RequestEntityTooLarge(w http.ResponseWriter, msg ...interface{})
func RequestTimeout ¶
func RequestTimeout(w http.ResponseWriter, msg ...interface{})
func RequestURITooLong ¶
func RequestURITooLong(w http.ResponseWriter, msg ...interface{})
func RequestedRangeNotSatisfiable ¶
func RequestedRangeNotSatisfiable(w http.ResponseWriter, msg ...interface{})
func ResetContent ¶
func ResetContent(w http.ResponseWriter, msg ...interface{})
func SeeOther ¶
func SeeOther(w http.ResponseWriter, msg ...interface{})
func ServiceUnavailable ¶
func ServiceUnavailable(w http.ResponseWriter, msg ...interface{})
func SwitchingProtocols ¶
func SwitchingProtocols(w http.ResponseWriter, msg ...interface{})
func Teapot ¶
func Teapot(w http.ResponseWriter, msg ...interface{})
func TemporaryRedirect ¶
func TemporaryRedirect(w http.ResponseWriter, msg ...interface{})
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, msg ...interface{})
func UnsupportedMediaType ¶
func UnsupportedMediaType(w http.ResponseWriter, msg ...interface{})
func UseProxy ¶
func UseProxy(w http.ResponseWriter, msg ...interface{})
func XML ¶
func XML(w ResponseWriter, val interface{}, code ...int)
Types ¶
type Cors ¶
type Cors struct {
// contains filtered or unexported fields
}
func CorsAllowAll ¶
func CorsAllowAll() *Cors
func NewCors ¶
func NewCors(options CorsOptions) *Cors
func (*Cors) MiddleWare ¶
type CorsOptions ¶
type Handler ¶
type Handler func(w ResponseWriter, r *http.Request, a lokas.IProcess)
func CreateHandler ¶
type MatcherFunc ¶
type MatcherFunc func(*http.Request, *RouteMatch) bool
func (MatcherFunc) Match ¶
func (m MatcherFunc) Match(this *http.Request, match *RouteMatch) bool
type MiddleWare ¶
type MiddleWare func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler)
type MiddlewareFunc ¶
MiddlewareFunc is a function which receives an http.Handler and returns another http.Handlethis. Typically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed to it, and then calls the handler passed as parameter to the MiddlewareFunc.
func CORSMethodMiddleware ¶
func CORSMethodMiddleware(this *Router) MiddlewareFunc
CORSMethodMiddleware automatically sets the Access-Control-Allow-Methods response header on requests for routes that have an OPTIONS method matcher to all the method matchers on the route. Routes that do not explicitly handle OPTIONS requests will not be processed by the middleware. See examples for usage.
func InitMiddleWare ¶
func InitMiddleWare(f func(w ResponseWriter, r *http.Request, a lokas.IProcess, next http.Handler), a lokas.IProcess) MiddlewareFunc
func (MiddlewareFunc) Middleware ¶
func (mw MiddlewareFunc) Middleware(handler http.Handler) http.Handler
Middleware allows MiddlewareFunc to implement the middleware interface.
type MiddlewareMatcher ¶
type PanicFormatter ¶
type PanicFormatter interface {
FormatPanicError(rw http.ResponseWriter, r *http.Request, infos *PanicInformation)
}
type PanicInformation ¶
func (*PanicInformation) RequestDescription ¶
func (p *PanicInformation) RequestDescription() string
func (*PanicInformation) StackAsString ¶
func (p *PanicInformation) StackAsString() string
type Recovery ¶
type Recovery struct { PrintStack bool LogStack bool PanicHandlerFunc func(*PanicInformation) StackAll bool StackSize int Formatter PanicFormatter }
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher Status() int Written() bool Size() int Before(func(ResponseWriter)) GetResponse() map[string]interface{} Text() string SetText(msg string) SetMap(m map[string]interface{}) AddContent(k string, v interface{}) AddData(k string, v interface{}) AddContext(k string, v interface{}) GetContext(k string) interface{} WriteContent() error Response(code int, msg ...interface{}) OK(msg ...interface{}) Failed(code protocol.ErrCode) JSON(val interface{}, code ...int) XML(val interface{}, code ...int) }
func NewResponseWriter ¶
func NewResponseWriter(this http.ResponseWriter) ResponseWriter
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func CurrentRoute ¶
func (*Route) BuildVarsFunc ¶
func (this *Route) BuildVarsFunc(f BuildVarsFunc) *Route
func (*Route) GetHandler ¶
func (*Route) GetHostTemplate ¶
func (*Route) GetMethods ¶
func (*Route) GetPathRegexp ¶
func (*Route) GetPathTemplate ¶
func (*Route) GetQueriesRegexp ¶
func (*Route) GetQueriesTemplates ¶
func (*Route) HandlerFunc ¶
func (*Route) HeadersRegexp ¶
func (*Route) MatcherFunc ¶
func (this *Route) MatcherFunc(f MatcherFunc) *Route
func (*Route) PathPrefix ¶
type RouteMatch ¶
type Router ¶
type Router struct { NotFoundHandler http.Handler MethodNotAllowedHandler http.Handler KeepContext bool // contains filtered or unexported fields }
func (*Router) BuildVarsFunc ¶
func (this *Router) BuildVarsFunc(f BuildVarsFunc) *Route
func (*Router) HandleFunc ¶
func (*Router) MatcherFunc ¶
func (this *Router) MatcherFunc(f MatcherFunc) *Route
func (*Router) PathExcept ¶
func (this *Router) PathExcept(p string, mwf ...MiddlewareFunc)
func (*Router) PathExcepts ¶
func (this *Router) PathExcepts(p []string, mwf ...MiddlewareFunc)
func (*Router) PathIn ¶
func (this *Router) PathIn(p []string, mwf ...MiddlewareFunc)
func (*Router) PathOnly ¶
func (this *Router) PathOnly(p string, mwf ...MiddlewareFunc)
func (*Router) PathPrefix ¶
func (*Router) StrictSlash ¶
func (*Router) Use ¶
func (this *Router) Use(mwf ...MiddlewareFunc)
Use appends a MiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify requests and/or responses, and are executed in the order that they are applied to the Routethis.
func (*Router) UseEncodedPath ¶
func (*Router) When ¶
func (this *Router) When(match MiddlewareMatcher, mwf ...MiddlewareFunc)
type Static ¶
type Static struct { Dir http.FileSystem Prefix string IndexFile string }
func NewStatic ¶
func NewStatic(directory http.FileSystem) *Static
func (*Static) MiddleWare ¶
type TextPanicFormatter ¶
type TextPanicFormatter struct{}
func (*TextPanicFormatter) FormatPanicError ¶
func (t *TextPanicFormatter) FormatPanicError(rw http.ResponseWriter, r *http.Request, infos *PanicInformation)