handywares

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

README

Handywares Coverage Badge

Usage

go get github.com/janstoon/toolbox/handywares

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CorsAllowHeaders = func(headers ...string) CorsHttpMiddlewareOpt {
	return func(s *cors.Options) {
		s.AllowedHeaders = headers
	}
}
View Source
var CorsAllowMethods = func(methods ...string) CorsHttpMiddlewareOpt {
	return func(s *cors.Options) {
		s.AllowedMethods = methods
	}
}
View Source
var CorsAllowOrigins = func(origins ...string) CorsHttpMiddlewareOpt {
	return func(s *cors.Options) {
		s.AllowedOrigins = origins
	}
}
View Source
var CorsDebug = func(debug bool) CorsHttpMiddlewareOpt {
	return func(s *cors.Options) {
		s.Debug = debug
	}
}

Functions

func AsynqCompensatorMiddleware added in v0.2.5

func AsynqCompensatorMiddleware(options ...CompensatorAsynqMiddlewareOpt) tricks.Middleware[asynq.Handler]

AsynqCompensatorMiddleware tries to compensate the task if max retries reached or error is not bricks.ErrRetryable. It searches for a bricks.Compensator in returned error by task handler and runs the first one.

func AsynqErrorDecoratorMiddleware added in v0.2.5

func AsynqErrorDecoratorMiddleware(options ...ErrorDecoratorAsynqMiddlewareOpt) tricks.Middleware[asynq.Handler]

AsynqErrorDecoratorMiddleware skip asynq retry except that error is bricks.ErrRetryable

func AsynqOpenTelemetryMiddleware added in v0.2.0

func AsynqOpenTelemetryMiddleware(
	tracer trace.Tracer, options ...OpenTelemetryAsynqMiddlewareOpt,
) tricks.Middleware[asynq.Handler]

func AsynqPanicRecoverMiddleware added in v0.2.0

func AsynqPanicRecoverMiddleware(options ...PanicRecoverAsynqMiddlewareOpt) tricks.Middleware[asynq.Handler]

func BricksErrorToHttpStatusMapper added in v0.2.3

func BricksErrorToHttpStatusMapper(err error) int

func BricksToGrpcErrorMapper added in v0.2.2

func BricksToGrpcErrorMapper(err error) error

func GrpcOpenTelemetryMiddleware added in v0.3.0

func GrpcOpenTelemetryMiddleware(
	tracer trace.Tracer, options ...OpenTelemetryGrpcMiddlewareOpt,
) tricks.Middleware[grpc.UnaryServerInterceptor]

func GrpcPanicRecoverMiddleware added in v0.3.0

func GrpcPanicRecoverMiddleware(
	options ...PanicRecoverGrpcMiddlewareOpt,
) tricks.Middleware[grpc.UnaryServerInterceptor]

func GrpcToBricksErrorMapper added in v0.2.3

func GrpcToBricksErrorMapper(err error) error

func GrpcUnaryClientErrorMapperMiddleware added in v0.2.3

func GrpcUnaryClientErrorMapperMiddleware(mapper func(error) error) tricks.Middleware[grpc.UnaryClientInterceptor]

func GrpcUnaryClientInvokerInterceptor added in v0.2.3

func GrpcUnaryClientInvokerInterceptor(
	ctx context.Context, method string, req, reply any,
	cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption,
) error

func GrpcUnaryServerErrorMapperMiddleware added in v0.2.2

func GrpcUnaryServerErrorMapperMiddleware(mapper func(error) error) tricks.Middleware[grpc.UnaryServerInterceptor]

func GrpcUnaryServerInvokeHandlerInterceptor added in v0.2.2

func GrpcUnaryServerInvokeHandlerInterceptor(
	ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler,
) (any, error)

func HttpBlindLoggerMiddleware added in v0.2.0

func HttpBlindLoggerMiddleware(
	mctx *middleware.Context, options ...BlindLoggerHttpMiddlewareOpt,
) tricks.Middleware[http.Handler]

func HttpBlindLoggerTripperware added in v0.2.1

func HttpBlindLoggerTripperware(options ...BlindLoggerHttpTripperwareOpt) tricks.Middleware[http.RoundTripper]

func HttpCrossOriginResourceSharingPolicyMiddleware added in v0.2.0

func HttpCrossOriginResourceSharingPolicyMiddleware(options ...CorsHttpMiddlewareOpt) tricks.Middleware[http.Handler]

func HttpErrorMapperTripperware added in v0.2.0

func HttpErrorMapperTripperware(
	mapper func(*http.Response, error) (*http.Response, error),
) tricks.Middleware[http.RoundTripper]

func HttpOpenTelemetryMiddleware added in v0.2.0

func HttpOpenTelemetryMiddleware(
	tracer trace.Tracer, mctx *middleware.Context, options ...OpenTelemetryHttpMiddlewareOpt,
) tricks.Middleware[http.Handler]

func HttpPanicRecoverMiddleware added in v0.2.0

func HttpPanicRecoverMiddleware(options ...PanicRecoverHttpMiddlewareOpt) tricks.Middleware[http.Handler]

func HttpStatusToBricksError added in v0.5.0

func HttpStatusToBricksError(code int, err error) error

func HttpToBricksErrorMapper added in v0.2.0

func HttpToBricksErrorMapper(rsp *http.Response, err error) (*http.Response, error)

func NatsCompensatorMiddleware added in v0.4.0

func NatsCompensatorMiddleware(options ...CompensatorNatsMiddlewareOpt) tricks.Middleware[NatsMsgHandler]

NatsCompensatorMiddleware tries to compensate the task if error is not bricks.ErrRetryable. It searches for a bricks.Compensator in returned error by msg handler and runs the first one.

func NatsOpenTelemetryMiddleware added in v0.4.0

func NatsOpenTelemetryMiddleware(
	tracer trace.Tracer, options ...OpenTelemetryNatsMiddlewareOpt,
) tricks.Middleware[NatsMsgHandler]

func NatsPanicRecoverMiddleware added in v0.4.0

func NatsPanicRecoverMiddleware(options ...PanicRecoverAsynqMiddlewareOpt) tricks.Middleware[NatsMsgHandler]

Types

type AsynqMiddlewareStack added in v0.1.0

type AsynqMiddlewareStack = tricks.MiddlewareStack[asynq.Handler]

type BlindLoggerHttpMiddlewareOpt

type BlindLoggerHttpMiddlewareOpt = tricks.InPlaceOption[any]

type BlindLoggerHttpTripperwareOpt added in v0.2.1

type BlindLoggerHttpTripperwareOpt = tricks.InPlaceOption[any]

type CompensatorAsynqMiddlewareOpt added in v0.2.5

type CompensatorAsynqMiddlewareOpt = tricks.InPlaceOption[any]

type CompensatorNatsMiddlewareOpt added in v0.4.0

type CompensatorNatsMiddlewareOpt = tricks.InPlaceOption[any]

type CorsHttpMiddlewareOpt

type CorsHttpMiddlewareOpt = tricks.InPlaceOption[cors.Options]

type ErrorDecoratorAsynqMiddlewareOpt added in v0.2.5

type ErrorDecoratorAsynqMiddlewareOpt = tricks.InPlaceOption[any]

type GrpcUnaryClientMiddlewareStack added in v0.2.3

type GrpcUnaryClientMiddlewareStack = tricks.MiddlewareStack[grpc.UnaryClientInterceptor]

type GrpcUnaryServerMiddlewareStack added in v0.2.2

type GrpcUnaryServerMiddlewareStack = tricks.MiddlewareStack[grpc.UnaryServerInterceptor]

type HttpMiddlewareStack

type HttpMiddlewareStack = tricks.MiddlewareStack[http.Handler]

type HttpRoundTripperFunc added in v0.2.0

type HttpRoundTripperFunc func(*http.Request) (*http.Response, error)

func (HttpRoundTripperFunc) RoundTrip added in v0.2.0

func (fn HttpRoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

type HttpRouteTester added in v0.0.6

type HttpRouteTester func(route *middleware.MatchedRoute) bool

func CombineHttpRouteTesters added in v0.0.6

func CombineHttpRouteTesters(tt ...HttpRouteTester) HttpRouteTester

func PassthroughHttpRouteTester added in v0.0.6

func PassthroughHttpRouteTester(success bool) HttpRouteTester

type HttpTripperwareStack added in v0.2.0

type HttpTripperwareStack = tricks.MiddlewareStack[http.RoundTripper]

type NatsMiddlewareStack added in v0.4.0

type NatsMiddlewareStack = tricks.MiddlewareStack[NatsMsgHandler]

type NatsMsgHandler added in v0.4.0

type NatsMsgHandler func(ctx context.Context, msg *nats.Msg) error

type OpenTelemetryAsynqMiddlewareOpt added in v0.1.0

type OpenTelemetryAsynqMiddlewareOpt = tricks.Option[OtelAmw]

func OtelAsynqSpanNamePrefix added in v0.1.0

func OtelAsynqSpanNamePrefix(prefix string) OpenTelemetryAsynqMiddlewareOpt

type OpenTelemetryGrpcMiddlewareOpt added in v0.3.0

type OpenTelemetryGrpcMiddlewareOpt = tricks.Option[OtelGmw]

func OtelGrpcSpanNamePrefix added in v0.3.0

func OtelGrpcSpanNamePrefix(prefix string) OpenTelemetryGrpcMiddlewareOpt

type OpenTelemetryHttpMiddlewareOpt added in v0.0.4

type OpenTelemetryHttpMiddlewareOpt = tricks.Option[OtelHmw]

func OtelHttpOperationIdException added in v0.0.6

func OtelHttpOperationIdException(oids ...string) OpenTelemetryHttpMiddlewareOpt

func OtelHttpRouteTester added in v0.0.6

func OtelHttpRouteTester(tester HttpRouteTester) OpenTelemetryHttpMiddlewareOpt

func OtelHttpSpanNamePrefix added in v0.0.6

func OtelHttpSpanNamePrefix(prefix string) OpenTelemetryHttpMiddlewareOpt

type OpenTelemetryNatsMiddlewareOpt added in v0.4.0

type OpenTelemetryNatsMiddlewareOpt = tricks.Option[OtelNmw]

func OtelNatsSpanNamePrefix added in v0.4.0

func OtelNatsSpanNamePrefix(prefix string) OpenTelemetryNatsMiddlewareOpt

type OtelAmw added in v0.1.0

type OtelAmw struct {
	// contains filtered or unexported fields
}

type OtelGmw added in v0.3.0

type OtelGmw struct {
	// contains filtered or unexported fields
}

type OtelHmw added in v0.0.6

type OtelHmw struct {
	// contains filtered or unexported fields
}

type OtelNmw added in v0.4.0

type OtelNmw struct {
	// contains filtered or unexported fields
}

type PanicRecoverAsynqMiddlewareOpt added in v0.1.0

type PanicRecoverAsynqMiddlewareOpt = tricks.InPlaceOption[any]

type PanicRecoverGrpcMiddlewareOpt added in v0.3.0

type PanicRecoverGrpcMiddlewareOpt = tricks.InPlaceOption[any]

type PanicRecoverHttpMiddlewareOpt

type PanicRecoverHttpMiddlewareOpt = tricks.InPlaceOption[any]

type PanicRecoverNatsMiddlewareOpt added in v0.4.0

type PanicRecoverNatsMiddlewareOpt = tricks.InPlaceOption[any]

Jump to

Keyboard shortcuts

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