Documentation ¶
Index ¶
- Variables
- func Bytes(w http.ResponseWriter, status int, result []byte) error
- func Err(w http.ResponseWriter, err error) error
- func Get(r *http.Request, key interface{}) interface{}
- func GetLog(r *http.Request) l.Logger
- func GetTID(r *http.Request) string
- func GetToken(r *http.Request) string
- func Handler(handler HTTPHandlerFunc) http.HandlerFunc
- func JSON(w http.ResponseWriter, status int, result interface{}) error
- func ReadByContentType(r *http.Request, data interface{}) error
- func ReadJSON(r *http.Request, data interface{}) error
- func Status(w http.ResponseWriter, status int) error
- func Wrap(h HTTPHandlerFunc, wrappers ...HTTPHandlerWrapper) http.HandlerFunc
- func WriteByAccept(w http.ResponseWriter, r *http.Request, status int, result interface{}) error
- type AuditHandler
- type Auditor
- type BaseHandler
- type ErrorHandler
- type HTTPHandler
- type HTTPHandlerFunc
- type HTTPHandlerWrapper
- type Identity
- type Keys
- type LogHandler
- type ResponseWriter
- type SimpleHTTPHandler
Constants ¶
This section is empty.
Variables ¶
var (
ContextKeys = Keys{
TID: "tid",
CID: "cid",
LOG: "requestLog",
TOKEN: "requestToken",
IDENTITY: "requestIdentity",
AUDITOR: "requestAuditor",
}
)
Functions ¶
func Handler ¶
func Handler(handler HTTPHandlerFunc) http.HandlerFunc
Handler wraps a library handler func nto a http handler func
func ReadByContentType ¶
ReadByContentType reads data from context using the Content-Type header to define the media type
func Wrap ¶
func Wrap(h HTTPHandlerFunc, wrappers ...HTTPHandlerWrapper) http.HandlerFunc
func WriteByAccept ¶
WriteByAccept writes data to context using the Accept header to define the media type
Types ¶
type AuditHandler ¶
type AuditHandler func(http.ResponseWriter, *http.Request) error
func (AuditHandler) ServeHTTP ¶
func (h AuditHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Auditor ¶
func GetAuditor ¶
type BaseHandler ¶
type BaseHandler struct { }
func (BaseHandler) Err ¶
func (h BaseHandler) Err(w http.ResponseWriter, err error) error
func (BaseHandler) JSON ¶
func (h BaseHandler) JSON(w http.ResponseWriter, status int, result interface{}) error
func (BaseHandler) Status ¶
func (h BaseHandler) Status(w http.ResponseWriter, status int) error
type ErrorHandler ¶
type ErrorHandler func(http.ResponseWriter, *http.Request) error
func (ErrorHandler) ServeHTTP ¶
func (h ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type HTTPHandler ¶
type HTTPHandler interface {
ServeHTTP(http.ResponseWriter, *http.Request) error
}
HTTPHandler is a contract for fast http handlers
type HTTPHandlerFunc ¶
type HTTPHandlerFunc func(http.ResponseWriter, *http.Request) error
HTTPHandlerFunc is a function to handle fasthttp requrests
func Audit ¶
func Audit(handler HTTPHandlerFunc) HTTPHandlerFunc
Audit wraps the provided HTTPHandlerFunc with access logging, error and audit control
func Error ¶
func Error(handler HTTPHandlerFunc) HTTPHandlerFunc
Error wraps the provided HTTPHandlerFunc with exception control
func Log ¶
func Log(handler HTTPHandlerFunc) HTTPHandlerFunc
Log wraps the provided HTTPHandlerFunc with access logging control
func (HTTPHandlerFunc) ServeHTTP ¶
func (h HTTPHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error
HandleRequest is the contract with HTTPHandler interface
type HTTPHandlerWrapper ¶
type HTTPHandlerWrapper func(HTTPHandlerFunc) HTTPHandlerFunc
HTTPHandlerWrapper is a function to create handler wraps to execute like a chain mechanism between the handlers
type Identity ¶
type Identity struct { Token string `json:"token"` Value interface{} `jsno:"value"` }
func GetIdentity ¶
type LogHandler ¶
type LogHandler func(http.ResponseWriter, *http.Request) error
func (LogHandler) ServeHTTP ¶
func (h LogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher // Status returns the status code of the response or 200 if the response has // not been written (as this is the default response code in net/http) Status() int // Written returns whether or not the ResponseWriter has been written. Written() bool // Size returns the size of the response body. Size() int }
ResponseWriter is a wrapper function to store status and body length of the request
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type SimpleHTTPHandler ¶
type SimpleHTTPHandler interface {
ServeHTTP(http.ResponseWriter, *http.Request)
}
SimpleHTTPHandler is a contract for fast http handlers