Documentation
¶
Overview ¶
Package ale is empty for now. Please look at the lower directories.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServeJSON ¶
func ServeJSON(w http.ResponseWriter, i interface{}, status ...int) error
ServeJSON marshals i and serves it on w. If the Content-Type header is not yet set on w, it will be set to "application/json; charset=utf-8". If status is passed, the first status value will be passed to w.WriteHeader, otherwise the default of http.StatusOK is used.
Types ¶
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request) error
ErrorHandlerFunc extends the standard http.HandlerFunc to support error handling more easily.
type ErrorReporter ¶
type ErrorReporter func(w http.ResponseWriter, r *http.Request, err error)
ErrorReporter is a function that can report an HTTP error returned by a ErrorHandlerFunc.
func (ErrorReporter) HTTPHandlerFunc ¶
func (c ErrorReporter) HTTPHandlerFunc(f ErrorHandlerFunc) http.HandlerFunc
HTTPHandlerFunc wraps an ErrorHandlerFunc, such that it can be used as a standard http.HandlerFunc
type LogContext ¶
type LogContext struct { // Request contains a shallow copy of the original request, without the // body. Request *http.Request // AuthUser is the name of the authenticated user, if any. AuthUser string // StatusCode is the HTTP status code sent to the client. StatusCode int // ResponseHeader is the list of header values sent to the client. ResponseHeader http.Header // ResponseHeader is the list of trailer values sent to the client. ResponseTrailer http.Header // ResponseBytes is the number of bytes written in the response body. ResponseBytes int64 // RequestBytes is the number of bytes read from the request body. This // can differ from the Content-Length value if reading is not completed, or // in case Content-Length is unset. RequestBytes int64 // StartTime is the time the request was received by the server StartTime time.Time // ElapsedTime is the duration it took to serve the request ElapsedTime time.Duration // contains filtered or unexported fields }
LogContext captures data about a request and response, for logging.
func NewLogContext ¶
func NewLogContext(w http.ResponseWriter, r *http.Request) *LogContext
NewLogContext returns a new log context, which should be used as a ResponseWriter for subsequent handlers in middleware.
Example:
func LogMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { logCtx := NewLogContext(w,r) next.ServeHTTP(logCtx, r) logCtx.Finalize() // Log logCtx here }) }
func (*LogContext) Finalize ¶
func (l *LogContext) Finalize()
Finalize should be called after ServeHTTP, to finalize the response values. Without this call, trailers will not be set, and elapsed time is not calculated.
func (*LogContext) Header ¶
func (l *LogContext) Header() http.Header
Header returns the header map that will be sent by WriteHeader.
func (*LogContext) Write ¶
func (l *LogContext) Write(p []byte) (int, error)
Write writes the data to the connection as part of an HTTP reply.
func (*LogContext) WriteHeader ¶
func (l *LogContext) WriteHeader(status int)
WriteHeader sends an HTTP response header with the provided status code.
Directories
¶
Path | Synopsis |
---|---|
Package donewriter provides a simple wrapper around an http.ResponseWriter to track when a response has been sent.
|
Package donewriter provides a simple wrapper around an http.ResponseWriter to track when a response has been sent. |
Package envconf provides simple functionality for reading configuration from the environment, such as for use within a 12-Factor Application.
|
Package envconf provides simple functionality for reading configuration from the environment, such as for use within a 12-Factor Application. |
Package errors is a drop-in replacement for the errors package in the standard library, with extensions useful for developing web applications.
|
Package errors is a drop-in replacement for the errors package in the standard library, with extensions useful for developing web applications. |
Package httperr provides HTTP-centric extensions to standard errors.
|
Package httperr provides HTTP-centric extensions to standard errors. |
Package panicerr makes it easy to recover panics, and convert them to standard errors.
|
Package panicerr makes it easy to recover panics, and convert them to standard errors. |
Package view provides an HTTP middleware to provide a simple View, based on Go templates.
|
Package view provides an HTTP middleware to provide a simple View, based on Go templates. |