Documentation ¶
Index ¶
- Variables
- func CORSAcceptAll(next http.Handler) http.Handler
- func ColourForStatus(code int) string
- func HumanSize(size int) string
- func HumanSizeSuffix(size int) string
- func JSON(rw http.ResponseWriter, v interface{}, code int)
- func JSONError(rw http.ResponseWriter, err error, code int)
- func MetadataMiddleware(next http.Handler) http.Handler
- type CORSConfig
- type Context
- type J
- type MiddlewareFunc
- type RequestMetadata
- type ResponseWriter
- func (s *ResponseWriter) Header() http.Header
- func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (s *ResponseWriter) Length() int
- func (s *ResponseWriter) Status() int
- func (s *ResponseWriter) Write(data []byte) (int, error)
- func (s *ResponseWriter) WriteHeader(statusCode int)
- type Router
- func (r *Router) Delete(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
- func (r *Router) Get(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
- func (r *Router) Handle(method, path string, handler http.Handler, middleware ...MiddlewareFunc)
- func (r *Router) HandleFunc(method, path string, handler func(http.ResponseWriter, *http.Request), ...)
- func (r *Router) Head(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
- func (r *Router) ListMiddleware() (mi []string)
- func (r *Router) Options(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
- func (r *Router) Patch(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
- func (r *Router) Post(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
- func (r *Router) Put(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
- func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (r *Router) SetMethodNotAllowed(h http.Handler)
- func (r *Router) SetNotFound(h http.Handler)
- func (r *Router) Static(relativePath, root string)
- func (r *Router) SubRouter(relativePath string, middleware ...MiddlewareFunc) *Router
- func (r *Router) Use(middleware ...MiddlewareFunc)
- func (r *Router) UseHandler(handler http.Handler)
Constants ¶
This section is empty.
Variables ¶
View Source
var AllowAllConfig = &CORSConfig{ AllowedMethods: []string{"*"}, AllowedOrigins: []string{"*"}, AllowedHeaders: []string{"Authorization", "X-Requested-With"}, }
View Source
var (
ResetColour = string([]byte{27, 91, 48, 109})
)
Functions ¶
func ColourForStatus ¶
func HumanSizeSuffix ¶
func JSON ¶
func JSON(rw http.ResponseWriter, v interface{}, code int)
Types ¶
type CORSConfig ¶
type Context ¶
type Context struct { context.Context io.ReadCloser Params httprouter.Params // contains filtered or unexported fields }
func GetContext ¶
type MiddlewareFunc ¶
func CORSMiddleware ¶
func CORSMiddleware(config *CORSConfig) MiddlewareFunc
type RequestMetadata ¶
type RequestMetadata struct { RequestID string Method string Path string Status int IP string Size int Latency time.Duration StartTime time.Time }
RequestMetadata generates metadata info for each request
func GetMetadata ¶
func GetMetadata(ctx *Context) (*RequestMetadata, bool)
FromContext extracts the metadata from the request
func (*RequestMetadata) Logger ¶
func (r *RequestMetadata) Logger() *log.Entry
Logger returns a logger that logs with the request fields
type ResponseWriter ¶
type ResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) *ResponseWriter
func (*ResponseWriter) Header ¶
func (s *ResponseWriter) Header() http.Header
func (*ResponseWriter) Hijack ¶
func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*ResponseWriter) Length ¶
func (s *ResponseWriter) Length() int
func (*ResponseWriter) Status ¶
func (s *ResponseWriter) Status() int
func (*ResponseWriter) WriteHeader ¶
func (s *ResponseWriter) WriteHeader(statusCode int)
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Delete ¶
func (r *Router) Delete(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
Delete registers a DELETE handler for the given path.
func (*Router) Get ¶
func (r *Router) Get(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
Get registers a GET handler for the given path.
func (*Router) Handle ¶
func (r *Router) Handle(method, path string, handler http.Handler, middleware ...MiddlewareFunc)
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(method, path string, handler func(http.ResponseWriter, *http.Request), middleware ...MiddlewareFunc)
func (*Router) Head ¶
func (r *Router) Head(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
func (*Router) ListMiddleware ¶
func (*Router) Options ¶
func (r *Router) Options(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
Options registers a OPTIONS handler for the given path.
func (*Router) Patch ¶
func (r *Router) Patch(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
Patch registers a PATCH handler for the given path.
func (*Router) Post ¶
func (r *Router) Post(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
Post registers a POST handler for the given path.
func (*Router) Put ¶
func (r *Router) Put(path string, handler http.HandlerFunc, middleware ...MiddlewareFunc)
Put registers a PUT handler for the given path.
func (*Router) SetMethodNotAllowed ¶
func (*Router) SetNotFound ¶
func (*Router) SubRouter ¶
func (r *Router) SubRouter(relativePath string, middleware ...MiddlewareFunc) *Router
func (*Router) Use ¶
func (r *Router) Use(middleware ...MiddlewareFunc)
func (*Router) UseHandler ¶
Click to show internal directories.
Click to hide internal directories.