Documentation
¶
Index ¶
- Variables
- func DefaultStacktracePred(status int) bool
- func LogOf(req *http.Request, w http.ResponseWriter) logger
- func Unlogged(req *http.Request, w http.ResponseWriter) http.ResponseWriter
- func WithTimeout(h httprouter.Handle, timeoutFunc timeoutFunc) httprouter.Handle
- type CORSSpec
- type Middleware
- type Nelly
- func (n *Nelly) Classic() Stack
- func (n *Nelly) RegisterMetrics()
- func (n *Nelly) SetCORS(cors CORSSpec)
- func (n *Nelly) SetRequestTimeout(timeout time.Duration)
- func (n *Nelly) SetRequiredHeaderValues(requiredHeaderValues map[string]string)
- func (n *Nelly) SetRequiredHeaders(requiredHeaders []string)
- func (n *Nelly) WithCORS(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithCacheControl(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithInstrument(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithLogging(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithPanicRecovery(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithRequiredHeaderValues(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithRequiredHeaders(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithTimeoutForNonLongRunningRequests(handler httprouter.Handle) httprouter.Handle
- func (n *Nelly) WithTrace(handler httprouter.Handle) httprouter.Handle
- type ResponseWriterDelegator
- type Stack
- type StacktracePred
Constants ¶
This section is empty.
Variables ¶
var ( DroppedRequests = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "nelly_dropped_requests_total", Help: "Number of requests dropped with 'Try again later' response", }, []string{"requestKind"}, ) )
Functions ¶
func DefaultStacktracePred ¶
func LogOf ¶
func LogOf(req *http.Request, w http.ResponseWriter) logger
LogOf returns the logger hiding in w. If there is not an existing logger then a passthroughLogger will be created which will log to stdout immediately when Addf is called.
func Unlogged ¶
func Unlogged(req *http.Request, w http.ResponseWriter) http.ResponseWriter
Unlogged returns the original ResponseWriter, or w if it is not our inserted logger.
func WithTimeout ¶
func WithTimeout(h httprouter.Handle, timeoutFunc timeoutFunc) httprouter.Handle
WithTimeout returns an http.Handler that runs h with a timeout determined by timeoutFunc. The new http.Handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler responds with a 504 Gateway Timeout error and the message provided. (If msg is empty, a suitable default message will be sent.) After the handler times out, writes by h to its http.ResponseWriter will return http.ErrHandlerTimeout. If timeoutFunc returns a nil timeout channel, no timeout will be enforced. recordFn is a function that will be invoked whenever a timeout happens.
Types ¶
type Middleware ¶
type Middleware func(httprouter.Handle) httprouter.Handle
type Nelly ¶
type Nelly struct { CORS CORSSpec RequiredHeaders []string RequiredHeaderValues map[string]string RequestTimeout time.Duration }
func (*Nelly) RegisterMetrics ¶
func (n *Nelly) RegisterMetrics()
func (*Nelly) SetRequestTimeout ¶
func (*Nelly) SetRequiredHeaderValues ¶
func (*Nelly) SetRequiredHeaders ¶
func (*Nelly) WithCORS ¶
func (n *Nelly) WithCORS(handler httprouter.Handle) httprouter.Handle
WithCORS is a simple CORS implementation that wraps an http Handler. Pass nil for allowedMethods and allowedHeaders to use the defaults. If allowedOriginPatterns is empty or nil, no CORS support is installed.
func (*Nelly) WithCacheControl ¶
func (n *Nelly) WithCacheControl(handler httprouter.Handle) httprouter.Handle
WithCacheControl sets the Cache-Control header to "no-cache, private" because all servers are protected by authn/authz. see https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#defining_optimal_cache-control_policy
func (*Nelly) WithInstrument ¶
func (n *Nelly) WithInstrument(handler httprouter.Handle) httprouter.Handle
func (*Nelly) WithLogging ¶
func (n *Nelly) WithLogging(handler httprouter.Handle) httprouter.Handle
func (*Nelly) WithPanicRecovery ¶
func (n *Nelly) WithPanicRecovery(handler httprouter.Handle) httprouter.Handle
func (*Nelly) WithRequiredHeaderValues ¶
func (n *Nelly) WithRequiredHeaderValues(handler httprouter.Handle) httprouter.Handle
func (*Nelly) WithRequiredHeaders ¶
func (n *Nelly) WithRequiredHeaders(handler httprouter.Handle) httprouter.Handle
func (*Nelly) WithTimeoutForNonLongRunningRequests ¶
func (n *Nelly) WithTimeoutForNonLongRunningRequests(handler httprouter.Handle) httprouter.Handle
func (*Nelly) WithTrace ¶
func (n *Nelly) WithTrace(handler httprouter.Handle) httprouter.Handle
type ResponseWriterDelegator ¶
type ResponseWriterDelegator struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseWriterDelegator interface wraps http.ResponseWriter to additionally record content-length, status-code, etc.
func (*ResponseWriterDelegator) ContentLength ¶
func (r *ResponseWriterDelegator) ContentLength() int
func (*ResponseWriterDelegator) Status ¶
func (r *ResponseWriterDelegator) Status() int
func (*ResponseWriterDelegator) Write ¶
func (r *ResponseWriterDelegator) Write(b []byte) (int, error)
func (*ResponseWriterDelegator) WriteHeader ¶
func (r *ResponseWriterDelegator) WriteHeader(code int)
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
func NewStack ¶
func NewStack(middlewares ...Middleware) Stack
func (Stack) Append ¶
func (s Stack) Append(middlewares ...Middleware) Stack
func (Stack) Then ¶
func (s Stack) Then(h httprouter.Handle) httprouter.Handle
type StacktracePred ¶
StacktracePred returns true if a stacktrace should be logged for this status.
func StatusIsNot ¶
func StatusIsNot(statuses ...int) StacktracePred
StatusIsNot returns a StacktracePred which will cause stacktraces to be logged for any status *not* in the given list.