Documentation ¶
Index ¶
- Variables
- func ClientUserHeaderInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- func IsWSHandshakeRequest(req *http.Request) bool
- func MakeLabelValue(path string) string
- func ServerInstrumentInterceptor(hist *prometheus.HistogramVec) grpc.UnaryServerInterceptor
- func ServerUserHeaderInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- type ErrorHandler
- type Func
- type GRPCServerLog
- type HeaderAdder
- type Instrument
- type Interface
- type Log
- type RouteMatcher
Constants ¶
This section is empty.
Variables ¶
var AuthenticateUser = Func(func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, ctx, err := user.ExtractOrgIDFromHTTPRequest(r) if err != nil { http.Error(w, err.Error(), http.StatusUnauthorized) return } next.ServeHTTP(w, r.WithContext(ctx)) }) })
AuthenticateUser propagates the user ID from HTTP headers back to the request's context.
var Logging = Log{}
Logging middleware logs each HTTP request method, path, response code and duration for all HTTP requests.
Functions ¶
func ClientUserHeaderInterceptor ¶
func ClientUserHeaderInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
ClientUserHeaderInterceptor propagates the user ID from the context to gRPC metadata, which eventually ends up as a HTTP2 header.
func IsWSHandshakeRequest ¶
IsWSHandshakeRequest returns true if the given request is a websocket handshake request.
func MakeLabelValue ¶
MakeLabelValue converts a Gorilla mux path to a string suitable for use in a Prometheus label value.
func ServerInstrumentInterceptor ¶
func ServerInstrumentInterceptor(hist *prometheus.HistogramVec) grpc.UnaryServerInterceptor
ServerInstrumentInterceptor instruments gRPC requests for errors and latency.
func ServerUserHeaderInterceptor ¶
func ServerUserHeaderInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
ServerUserHeaderInterceptor propagates the user ID from the gRPC metadata back to our context.
Types ¶
type ErrorHandler ¶
ErrorHandler lets you call an alternate http handler upon a certain response code. Note it will assume a 200 if the wrapped handler does not write anything
type GRPCServerLog ¶
type GRPCServerLog struct { // WithRequest will log the entire request rather than just the error WithRequest bool }
GRPCServerLog logs grpc requests, errors, and latency.
func (GRPCServerLog) UnaryServerInterceptor ¶
func (s GRPCServerLog) UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
UnaryServerInterceptor returns an interceptor that logs gRPC requests
type HeaderAdder ¶
HeaderAdder adds headers to responses
type Instrument ¶
type Instrument struct { RouteMatcher RouteMatcher Duration *prometheus.HistogramVec }
Instrument is a Middleware which records timings for every HTTP request
type Interface ¶
Interface is the shared contract for all middlesware, and allows middlesware to wrap handlers.
Identity is an Interface which doesn't do anything.
func Merge ¶
Merge produces a middleware that applies multiple middlesware in turn; ie Merge(f,g,h).Wrap(handler) == f.Wrap(g.Wrap(h.Wrap(handler)))
func PathReplace ¶
PathReplace replcase Request.RequestURI with the specified string.
type Log ¶
type Log struct {
LogRequestHeaders bool // LogRequestHeaders true -> dump http headers at debug log level
}
Log middleware logs http requests
type RouteMatcher ¶
type RouteMatcher interface {
Match(*http.Request, *mux.RouteMatch) bool
}
RouteMatcher matches routes