From c31555610f8e3ccbd1b50da653c6a9ad23b2f1e7 Mon Sep 17 00:00:00 2001 From: Petros Koutloubasis Date: Mon, 26 Jul 2021 09:13:28 +0200 Subject: [PATCH] Add global default ErrorFormatFunc Adds the possibility to set the default ErrorFormatFunc, so a consistend error formatting can be used without the need to initialize all multierrors with ErrorFormat field --- format.go | 3 +++ multierror.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/format.go b/format.go index 47f13c4..0679e7a 100644 --- a/format.go +++ b/format.go @@ -9,6 +9,9 @@ import ( // turn the list of errors into a string. type ErrorFormatFunc func([]error) string +// DefaultErrorFormatFunc is the default ErrorFormatFunc +var DefaultErrorFormatFunc = ListFormatFunc + // ListFormatFunc is a basic formatter that outputs the number of errors // that occurred along with a bullet point list of the errors. func ListFormatFunc(es []error) string { diff --git a/multierror.go b/multierror.go index f545743..de861a8 100644 --- a/multierror.go +++ b/multierror.go @@ -15,7 +15,7 @@ type Error struct { func (e *Error) Error() string { fn := e.ErrorFormat if fn == nil { - fn = ListFormatFunc + fn = DefaultErrorFormatFunc } return fn(e.Errors)