Documentation ¶
Index ¶
- func GetRequestID(r *http.Request) (string, bool)
- type Middleware
- func (m *Middleware) HTTPError(rw http.ResponseWriter, r *http.Request, msg string, code int, err error)
- func (m *Middleware) LogRequest(r *http.Request, status int, latency time.Duration)
- func (m *Middleware) Logger(handler http.Handler) http.Handler
- func (m *Middleware) Recovery(handler http.Handler) http.Handler
- func (m *Middleware) RequestID(handler http.Handler) http.Handler
- func (m *Middleware) Timeout(handler http.Handler, fallback time.Duration) http.Handler
- type TimeoutResponseWriter
- func (rw *TimeoutResponseWriter) Cancel() bool
- func (rw *TimeoutResponseWriter) Header() http.Header
- func (rw *TimeoutResponseWriter) ResponseWriter() http.ResponseWriter
- func (rw *TimeoutResponseWriter) Status() int
- func (rw *TimeoutResponseWriter) TimedOut() bool
- func (rw *TimeoutResponseWriter) Write(b []byte) (int, error)
- func (rw *TimeoutResponseWriter) WriteHeader(status int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Middleware ¶ added in v0.2.1
type Middleware struct {
// Log is the log output for this Middleware.
Log *logger.Logger
}
func (*Middleware) HTTPError ¶ added in v0.2.1
func (m *Middleware) HTTPError(rw http.ResponseWriter, r *http.Request, msg string, code int, err error)
HTTPError handles responding to a client with an HTTP error code and logs the provided error.
func (*Middleware) LogRequest ¶ added in v0.3.1
LogRequest will log a request with known response status and handler latency.
func (*Middleware) Logger ¶ added in v0.2.1
func (m *Middleware) Logger(handler http.Handler) http.Handler
Logger adds request logging to the provided HTTP handler.
func (*Middleware) Recovery ¶ added in v0.2.1
func (m *Middleware) Recovery(handler http.Handler) http.Handler
Recovery adds panic recovery (and panic logging) to the provided HTTP handler.
func (*Middleware) RequestID ¶ added in v0.3.1
func (m *Middleware) RequestID(handler http.Handler) http.Handler
RequestID provides setting unique IDs per request and adding a hook to the logger to append these to log entries using the request's context. This should be placed at the TOP of handler stack.
type TimeoutResponseWriter ¶ added in v0.3.0
type TimeoutResponseWriter struct {
// contains filtered or unexported fields
}
TimeoutResponseWriter wraps an http.ResponseWriter to add request timeout capabilities.
func (*TimeoutResponseWriter) Cancel ¶ added in v0.3.0
func (rw *TimeoutResponseWriter) Cancel() bool
Cancel will attempt to cancel the timeout counter.
func (*TimeoutResponseWriter) Header ¶ added in v0.3.0
func (rw *TimeoutResponseWriter) Header() http.Header
Header implements http.ResponseWriter's .Header().
func (*TimeoutResponseWriter) ResponseWriter ¶ added in v0.3.0
func (rw *TimeoutResponseWriter) ResponseWriter() http.ResponseWriter
ResponseWriter returns access to the underlying http.ResponseWriter.
func (*TimeoutResponseWriter) Status ¶ added in v0.3.0
func (rw *TimeoutResponseWriter) Status() int
Status returns the set response status code.
func (*TimeoutResponseWriter) TimedOut ¶ added in v0.3.0
func (rw *TimeoutResponseWriter) TimedOut() bool
TimedOut returns whether this TimeoutResponseWriter has timed out.
func (*TimeoutResponseWriter) Write ¶ added in v0.3.0
func (rw *TimeoutResponseWriter) Write(b []byte) (int, error)
Write implements http.ResponseWriter's .Write().
func (*TimeoutResponseWriter) WriteHeader ¶ added in v0.3.0
func (rw *TimeoutResponseWriter) WriteHeader(status int)
WriteHeader implements http.ResponseWriter's .WriteHeader().