Documentation ¶
Index ¶
- Constants
- func DefaultAfter(entry *log.Entry, res ResponseWriter, latency time.Duration, name string) *log.Entry
- func DefaultBefore(entry *log.Entry, req *http.Request, remoteAddr string) *log.Entry
- func NewAuthMiddleware(opts *AuthOptions) func(h http.Handler) http.Handler
- type AfterFunc
- type AuthOptions
- type BeforeFunc
- type Middleware
- type ResponseWriter
Constants ¶
const (
// UserIDHeader is the name of the HTTP header used to identify the user
UserIDHeader = "X-DLaaS-UserID"
)
Variables ¶
This section is empty.
Functions ¶
func DefaultAfter ¶
func DefaultAfter(entry *log.Entry, res ResponseWriter, latency time.Duration, name string) *log.Entry
DefaultAfter is the default func assigned to *Middleware.After
func DefaultBefore ¶
DefaultBefore is the default func assigned to *Middleware.Before
func NewAuthMiddleware ¶
func NewAuthMiddleware(opts *AuthOptions) func(h http.Handler) http.Handler
NewAuthMiddleware creates a new http.Handler that adds authentication logic to a given Handler
Types ¶
type AfterFunc ¶
AfterFunc is the func type used to modify or replace the *logrus.Entry after calling the next func in the middleware chain
type AuthOptions ¶
type AuthOptions struct {
ExcludedURLs []string
}
AuthOptions for the auth middleware.
type BeforeFunc ¶
BeforeFunc is the func type used to modify or replace the *logrus.Entry prior to calling the next func in the middleware chain
type Middleware ¶
type Middleware struct { Name string // Name is the name of the application as recorded in latency metrics Before func(*log.Entry, *http.Request, string) *log.Entry After func(*log.Entry, ResponseWriter, time.Duration, string) *log.Entry // contains filtered or unexported fields }
Middleware is a middleware handler that logs the request as it goes in and the response as it goes out.
func NewLoggingMiddleware ¶
func NewLoggingMiddleware(name string) *Middleware
NewLoggingMiddleware returns a new *Middleware.
func (*Middleware) ExcludeURL ¶
func (m *Middleware) ExcludeURL(u string) error
ExcludeURL adds a new URL u to be ignored during logging. The URL u is parsed, hence the returned error
func (*Middleware) ExcludedURLs ¶
func (m *Middleware) ExcludedURLs() []string
ExcludedURLs returns the list of excluded URLs for this middleware
func (*Middleware) Handle ¶
func (m *Middleware) Handle(next http.Handler) http.Handler
Handle is the main entrypoint for the middleware to process the request
func (*Middleware) SetLogStarting ¶
func (m *Middleware) SetLogStarting(v bool)
SetLogStarting accepts a bool to control the logging of "started handling request" prior to passing to the next middleware
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 // Before allows for a function to be called before the ResponseWriter has been written to. This is // useful for setting headers or any other operations that must happen before a response has been written. Before(func(ResponseWriter)) }
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter