Documentation ¶
Index ¶
- Constants
- func IgnoreHandler(next http.Handler) http.Handler
- func Middleware(log Logger, next http.Handler) http.Handler
- func RemoteAddr(r *http.Request) string
- func RequestURI(r *http.Request) string
- func SetShouldIgnore(ctx context.Context, ignore bool) bool
- func ShouldIgnore(ctx context.Context) bool
- func Username(r *http.Request) string
- type Details
- type Logger
- type ResponseStatus
Constants ¶
const Message string = "access request"
Variables ¶
This section is empty.
Functions ¶
func IgnoreHandler ¶ added in v0.3.0
IgnoreHandler returns a http.Handler that marks the http.Request as "should ignore".
func Middleware ¶
Middleware wraps a http.Handler so it's request and response details are tracked and send to Logger log.
func RemoteAddr ¶
RemoteAddr returns a sanitized remote address from the http.Request.
func RequestURI ¶
RequestURI https://www.rfc-editor.org/rfc/rfc7540#section-8.3
func SetShouldIgnore ¶ added in v0.2.0
SetShouldIgnore marks the context from a http.Request as "should ignore". It return true if the context was successfully updated. If the context does not already contain a reference to
func ShouldIgnore ¶ added in v0.2.0
ShouldIgnore returns if the http.Request's context contains a "should ignore" value set using SetShouldIgnore.
Types ¶
type Details ¶
type Details struct { ServerName string HandlerName string UserAgent string // StatusCode is the first http response code passed to the // [http.ResponseWriter.WriteHeader]. See [httpsnoop.Metrics] for additional // information. StatusCode int // StartTime is the time the request was received. StartTime time.Time // Duration is the time it took to execute the handler. Duration time.Duration // BytesWritten is the number of bytes successfully written by the // [http.ResponseWriter.Write] or [http.ResponseWriter.ReadFrom] functions. // See [httpsnoop.Metrics] for additional information. BytesWritten int64 // RequestCount is the amount of open requests during the execution of the // handler. RequestCount int64 }
Details are collected with Middleware and contain additional details of a request and it's corresponding response.
type Logger ¶
func DefaultLogger ¶
func LimitCodes ¶
func LimitCodes(rs ResponseStatus, next Logger) Logger
type ResponseStatus ¶
type ResponseStatus int
const ( ResponseStatusSuccess ResponseStatus = 1 << iota // 200-299 ResponseStatusRedirect // 300-399 ResponseStatusClientError // 400-499 ResponseStatusServerError // 500-599 ResponseStatusNone ResponseStatus = 0 ResponseStatusAll = ResponseStatusSuccess | ResponseStatusRedirect | ResponseStatusClientError | ResponseStatusServerError ResponseStatusErrors = ResponseStatusClientError | ResponseStatusServerError )
func (ResponseStatus) InRange ¶
func (l ResponseStatus) InRange(statusCode int) bool