util

package
v0.1.2-rc4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrClientCanceled   = "The request was cancelled by the client."
	ErrDeadlineExceeded = "" /* 160-byte string literal not displayed */
)
View Source
const StatusClientClosedRequest = 499

StatusClientClosedRequest is the status code for when a client request cancellation of an http request

Variables

View Source
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))
)
View Source
var Logger = log.NewNopLogger()

Logger is a global logger to use only where you cannot inject a logger.

Functions

func ClientHTTPStatusAndError

func ClientHTTPStatusAndError(err error) (int, error)

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

func InstrumentedHTTPClient() *http.Client

InstrumentedHTTPClient returns a HTTP client with tracing instrumented default RoundTripper.

func IsWSHandshakeRequest added in v0.1.1

func IsWSHandshakeRequest(req *http.Request) bool

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 UnsafeGetBytes(s string) []byte

func UnsafeGetString

func UnsafeGetString(buf []byte) string

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

func YAMLMarshalUnmarshal(in interface{}) (map[string]interface{}, error)

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

func (Log) Wrap added in v0.1.1

func (l Log) Wrap(next http.Handler) http.Handler

Wrap implements Middleware

type RoundTripperFunc

type RoundTripperFunc func(req *http.Request) (*http.Response, error)

func (RoundTripperFunc) RoundTrip

func (f RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL