Documentation
¶
Index ¶
- Constants
- Variables
- func ClientHTTPStatusAndError(err error) (int, error)
- func DiffConfig(defaultConfig, actualConfig map[interface{}]interface{}) (map[interface{}]interface{}, error)
- func InstrumentedHTTPClient() *http.Client
- func IsWSHandshakeRequest(req *http.Request) bool
- func NewHTTPMetricMiddleware(mux *mux.Router, namespace string, reg prometheus.Registerer) (middleware.Interface, error)
- func UnsafeGetBytes(s string) []byte
- func UnsafeGetString(buf []byte) string
- func WrapWithInstrumentedHTTPTransport(next http.RoundTripper) http.RoundTripper
- func WriteError(err error, w http.ResponseWriter)
- func WriteYAMLResponse(w http.ResponseWriter, v interface{})
- func YAMLMarshalUnmarshal(in interface{}) (map[string]interface{}, error)
- type Log
- type RoundTripperFunc
Constants ¶
const ( ErrClientCanceled = "The request was cancelled by the client." ErrDeadlineExceeded = "" /* 160-byte string literal not displayed */ )
const StatusClientClosedRequest = 499
StatusClientClosedRequest is the status code for when a client request cancellation of an http request
Variables ¶
var ( RecoveryHTTPMiddleware = middleware.Func(func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { defer func() { if p := recover(); p != nil { WriteError(onPanic(p), w) } }() next.ServeHTTP(w, req) }) }) RecoveryGRPCStreamInterceptor = grpc_recovery.StreamServerInterceptor(grpc_recovery.WithRecoveryHandler(onPanic)) RecoveryGRPCUnaryInterceptor = grpc_recovery.UnaryServerInterceptor(grpc_recovery.WithRecoveryHandler(onPanic)) )
var Logger = log.NewNopLogger()
Logger is a global logger to use only where you cannot inject a logger.
Functions ¶
func ClientHTTPStatusAndError ¶
ClientHTTPStatusAndError returns error and http status that is "safe" to return to client without exposing any implementation details.
func DiffConfig ¶
func DiffConfig(defaultConfig, actualConfig map[interface{}]interface{}) (map[interface{}]interface{}, error)
DiffConfig utility function that returns the diff between two config map objects
func InstrumentedHTTPClient ¶
InstrumentedHTTPClient returns a HTTP client with tracing instrumented default RoundTripper.
func IsWSHandshakeRequest ¶ added in v0.1.1
IsWSHandshakeRequest returns true if the given request is a websocket handshake request.
func NewHTTPMetricMiddleware ¶ added in v0.1.1
func NewHTTPMetricMiddleware(mux *mux.Router, namespace string, reg prometheus.Registerer) (middleware.Interface, error)
NewHTTPMetricMiddleware creates a new middleware that automatically instruments HTTP requests from the given router.
func UnsafeGetBytes ¶
func UnsafeGetString ¶
func WrapWithInstrumentedHTTPTransport ¶
func WrapWithInstrumentedHTTPTransport(next http.RoundTripper) http.RoundTripper
WrapWithInstrumentedHTTPTransport wraps the given RoundTripper with an tracing instrumented one.
func WriteError ¶
func WriteError(err error, w http.ResponseWriter)
WriteError write a go error with the correct status code.
func WriteYAMLResponse ¶
func WriteYAMLResponse(w http.ResponseWriter, v interface{})
WriteYAMLResponse writes some YAML as a HTTP response.
func YAMLMarshalUnmarshal ¶
YAMLMarshalUnmarshal utility function that converts a YAML interface in a map doing marshal and unmarshal of the parameter
Types ¶
type Log ¶ added in v0.1.1
type Log struct { Log logging.Interface LogRequestHeaders bool // LogRequestHeaders true -> dump http headers at debug log level LogRequestAtInfoLevel bool // LogRequestAtInfoLevel true -> log requests at info log level SourceIPs *middleware.SourceIPExtractor }
Log middleware logs http requests