util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContextKeyCluster is the key used to put and retrieve
	// `*model.RequestCluster` into context.
	ContextKeyCluster contextKey = iota
)
View Source
const (
	StatusCodeKey = "koko-status-code"
)

Variables

View Source
var LoggerKey loggerKey
View Source
var SpanKey spanKey

Functions

func ErrorHandler

func ErrorHandler(ctx context.Context,
	mux *runtime.ServeMux, m runtime.Marshaler,
	w http.ResponseWriter, r *http.Request, err error,
)

func FinishTrace

func FinishTrace(ctx context.Context,
	_ http.ResponseWriter, _ proto2.Message,
) error

func HandleErr

func HandleErr(ctx context.Context, logger *zap.Logger, err error) error

func HandlerWithLogger

func HandlerWithLogger(handler http.Handler, logger *zap.Logger) http.Handler

func HandlerWithRecovery

func HandlerWithRecovery(handler http.Handler, logger *zap.Logger) http.Handler

HandlerWithRecovery is http handler middleware that gracefully handles panics by calling a deferred recover for all wrapped handlers. When a panic is encountered, a generic error message and response code 500 are returned to the client. More detailed error information is logged if the service log level is set to Error or higher.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *zap.Logger

func LoggerInterceptor

func LoggerInterceptor(logger *zap.Logger) grpc.UnaryServerInterceptor

func LoggerWithSpan

func LoggerWithSpan(ctx context.Context, l *zap.Logger) *zap.Logger

func PanicInterceptor

func PanicInterceptor(logger *zap.Logger) grpc.UnaryServerInterceptor

PanicInterceptor wraps the panic recovery handler grpcRecoveryHandler for use as a UnaryServerInterceptor.

func PanicStreamInterceptor

func PanicStreamInterceptor(logger *zap.Logger) grpc.StreamServerInterceptor

PanicStreamInterceptor wraps the panic recovery handler grpcRecoveryHandler for use as a StreamServerInterceptor.

func RequestContextWithLogger

func RequestContextWithLogger(req *http.Request, logger *zap.Logger) *http.Request

func SetHTTPStatus

func SetHTTPStatus(ctx context.Context, w http.ResponseWriter,
	_ proto2.Message,
) error

func SetHeader

func SetHeader(ctx context.Context, code int)

func SetSpanResource

func SetSpanResource(ctx context.Context)

Types

type DefaultStoreLoader

type DefaultStoreLoader struct {
	Store store.Store
}

func (DefaultStoreLoader) Load

type ErrClient

type ErrClient struct {
	Message string
}

func (ErrClient) Error

func (e ErrClient) Error() string

type Message

type Message = proto.Message

type SpanValue

type SpanValue interface {
	TraceIDLogKey() string
	SpanIDLogKey() string
	Resource() string
	TraceID() string
	SpanID() string
	SetResource(name string)
}

type StoreLoadErr

type StoreLoadErr struct {
	Code    codes.Code
	Message string
}

func (StoreLoadErr) Error

func (s StoreLoadErr) Error() string

type StoreLoader

type StoreLoader interface {
	// Load returns the store to use for the request and cluster.
	// Cluster is derived from request and maybe nil.
	// Ctx is specific to request. It may be expanded in future to include
	// HTTP metadata as needed.
	// If err is of type StoreLoadErr,
	// corresponding GRPC status code and message are returned to the client.
	// For any other error, an internal error is returned to the client
	Load(ctx context.Context, cluster *model.RequestCluster) (store.Store, error)
}

Jump to

Keyboard shortcuts

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