Introduce ErrorHandlerFunc (#915)
Marat Reymers authored 3 years ago
Peter Bourgon committed 3 years ago
25 | 25 | func (h *LogErrorHandler) Handle(ctx context.Context, err error) { |
26 | 26 | h.logger.Log("err", err) |
27 | 27 | } |
28 | ||
29 | // The ErrorHandlerFunc type is an adapter to allow the use of | |
30 | // ordinary function as ErrorHandler. If f is a function | |
31 | // with the appropriate signature, ErrorHandlerFunc(f) is a | |
32 | // ErrorHandler that calls f. | |
33 | type ErrorHandlerFunc func(ctx context.Context, err error) | |
34 | ||
35 | // Handle calls f(ctx, err). | |
36 | func (f ErrorHandlerFunc) Handle(ctx context.Context, err error) { | |
37 | f(ctx, err) | |
38 | } |