Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultErrorFormatter = func(i int, err error, str *string) { *str = fmt.Sprintf("%s\n%d:%s", *str, i, err.Error()) }
DefaultErrorFormatter represents the default formatter for displaying the collection of errors.
Functions ¶
Types ¶
type DuplicatationOptions ¶
type DuplicatationOptions int
ErrorCollection can be configured to allow duplicates.
const ( AllowDuplicates DuplicatationOptions = 0 RejectDuplicatesIgnoreTimestamp DuplicatationOptions = 1 //Ignore timestamp information in JE struct RejectDuplicates DuplicatationOptions = 2 )
type ErrorCollection ¶
type ErrorCollection struct { DuplicatationOptions DuplicatationOptions Errors []error Formatter func(i int, err error, str *string) // contains filtered or unexported fields }
ErrorCollection allows multiple errors to be accumulated and then returned as a single error. ErrorCollection can be safely used by concurrent goroutines.
func NewErrorCollection ¶
func NewErrorCollection(dup ...DuplicatationOptions) *ErrorCollection
Creates a new empty ErrorCollection. When `dup` is set, any duplicate error message is discarded and not appended to the collection
func (*ErrorCollection) AddError ¶
func (ec *ErrorCollection) AddError(err error)
AddError appends an error to the error collection. It is safe to use from multiple concurrent goroutines.
func (*ErrorCollection) AddErrorCollection ¶
func (ec *ErrorCollection) AddErrorCollection(errs *ErrorCollection)
AddErrorCollection appends an entire ErrorCollection to the receiver error collection. It is safe to use from multiple concurrent goroutines.
func (*ErrorCollection) AddErrors ¶
func (ec *ErrorCollection) AddErrors(errs ...error)
AddErrors appends multiple errors to the error collection. It is safe to use from multiple concurrent goroutines.
func (*ErrorCollection) Error ¶
func (ec *ErrorCollection) Error() string
Error return a list of all contained errors. The output can be formatted by setting a custom Formatter.
type JE ¶
type JE struct { Code int Domain string DisplayTime bool // contains filtered or unexported fields }
JE allows errors to contain Code, Domain, Error and Message information. Only Code and Domain are exported so that once a JE struct is created, the key elements are static.
func NewAndDisplayTime ¶
NewAndDisplayTime creates a new JE struct and configures it to display the timestamp. Domain is optional but can be at most 1 string.
func (JE) Error ¶
Error generates a string that neatly formats the contents of the JE struct. JSONError satisfies the error interface. Useful with panic().