From 35521d625c91f834088efb919dbd4aeb00ac1850 Mon Sep 17 00:00:00 2001 From: Marat Reymers Date: Sat, 28 Sep 2019 22:57:02 +0300 Subject: [PATCH] Introduce ErrorHandlerFunc --- transport/error_handler.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/transport/error_handler.go b/transport/error_handler.go index 1095b9617..9f255966f 100644 --- a/transport/error_handler.go +++ b/transport/error_handler.go @@ -26,3 +26,14 @@ func NewLogErrorHandler(logger log.Logger) *LogErrorHandler { func (h *LogErrorHandler) Handle(ctx context.Context, err error) { h.logger.Log("err", err) } + +// The ErrorHandlerFunc type is an adapter to allow the use of +// ordinary function as ErrorHandler. If f is a function +// with the appropriate signature, ErrorHandlerFunc(f) is a +// ErrorHandler that calls f. +type ErrorHandlerFunc func(ctx context.Context, err error) + +// Handle calls f(ctx, err). +func (f ErrorHandlerFunc) Handle(ctx context.Context, err error) { + f(ctx, err) +}