From 3e4de635e8aa347e16f7e51372e4ddf9fc75d071 Mon Sep 17 00:00:00 2001 From: zhuwenkai Date: Fri, 8 Jul 2022 16:43:37 +0800 Subject: [PATCH] add a way to customize the format --- README.md | 10 ++++++++++ format.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71dd308..9095c64 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,16 @@ if result != nil { } ``` +or + +```go +func init() { + multierror.ListFormatFunc = func([]error) string { + return "errors!" + } +} +``` + **Accessing the list of errors** `multierror.Error` implements `error` so if the caller doesn't know about diff --git a/format.go b/format.go index 47f13c4..7b2b699 100644 --- a/format.go +++ b/format.go @@ -11,7 +11,7 @@ type ErrorFormatFunc func([]error) string // 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 { +var ListFormatFunc = func(es []error) string { if len(es) == 1 { return fmt.Sprintf("1 error occurred:\n\t* %s\n\n", es[0]) }