-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathformatter.go
35 lines (31 loc) · 1.04 KB
/
formatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package err2
import (
"github.com/lainio/err2/formatter"
fmtstore "github.com/lainio/err2/internal/formatter"
)
func init() {
SetFormatter(formatter.Decamel)
}
// SetFormatter sets the current formatter for the err2 package. The default
// [formatter.Decamel] processes function names to human readable and the
// idiomatic Go format, i.e. all lowercase, space delimiter, package names colon
// separated. The example how a quite complex method name gives a proper error
// message prefix:
//
// "ssi.(*DIDAgent).CreateWallet" -> "ssi: didagent create wallet"
//
// Following line sets a noop formatter where errors are taken as function names
// are in the call stack.
//
// err2.SetFormatter(formatter.Noop)
//
// You can make your own implementations of formatters. See more information
// in formatter package.
func SetFormatter(f formatter.Interface) {
fmtstore.SetFormatter(f)
}
// Returns the current formatter. See more information from [SetFormatter] and
// [formatter] package.
func Formatter() formatter.Interface {
return fmtstore.Formatter()
}