Documentation ¶
Index ¶
- func Fmt() func(e error)
- func Logger() func(e error)
- func Panic() func(e error)
- type Context
- type ErrorBox
- type ErrorCollection
- func (ec *ErrorCollection) Add(e error)
- func (ec *ErrorCollection) AddHandler(handler ...ErrorHandler)
- func (ec *ErrorCollection) AddHandlerWithContext(handler ...ErrorHandlerWithContextInSeries)
- func (ec *ErrorCollection) CatchError() <-chan error
- func (ec *ErrorCollection) Clear()
- func (ec *ErrorCollection) CloseHandles()
- func (ec *ErrorCollection) GetError() error
- func (ec *ErrorCollection) GetQueueLock() *sync.Mutex
- func (ec *ErrorCollection) Handle(f ErrorHandler)
- func (ec *ErrorCollection) HandleChain()
- func (ec *ErrorCollection) HandleInSeries(f ErrorHandlerWithContextInSeries)
- func (ec *ErrorCollection) IfErrorChanFull() bool
- func (ec *ErrorCollection) Length() int
- func (ec *ErrorCollection) Pop() error
- func (ec *ErrorCollection) SafeLength() int
- type ErrorHandler
- type ErrorHandlerWithContextInSeries
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
func NewContext ¶
func NewContext() *Context
type ErrorCollection ¶
type ErrorCollection struct { ErrorHandleChain []ErrorHandler // handler to deal with error ErrorHandleChainWithContextInSeires []ErrorHandlerWithContextInSeries // handler with a context and a flag 'next' to decide whether to handle next handler M *sync.Mutex // field lock RWlock CatchErrorChan chan error // when error in queue,it will be put into catchErrorChan AutoHandleChan chan int // used to close the channel // contains filtered or unexported fields }
func Default ¶
func Default() *ErrorCollection
func (*ErrorCollection) AddHandler ¶
func (ec *ErrorCollection) AddHandler(handler ...ErrorHandler)
Add handler to handler chain
func (*ErrorCollection) AddHandlerWithContext ¶
func (ec *ErrorCollection) AddHandlerWithContext(handler ...ErrorHandlerWithContextInSeries)
Add handler with context to handler chain
func (*ErrorCollection) CatchError ¶
func (ec *ErrorCollection) CatchError() <-chan error
When an error in , it will be pop into a chanel waiting for handling
func (*ErrorCollection) CloseHandles ¶
func (ec *ErrorCollection) CloseHandles()
func (*ErrorCollection) GetError ¶
func (ec *ErrorCollection) GetError() error
Get an error The error is from queue' head. When use Get(), it means the error is only for query,not deleted from the queue
func (*ErrorCollection) GetQueueLock ¶
func (ec *ErrorCollection) GetQueueLock() *sync.Mutex
func (*ErrorCollection) Handle ¶
func (ec *ErrorCollection) Handle(f ErrorHandler)
This is a self design function to handle the inner errors collected via a single handler typed 'ErrorHandler'
func (*ErrorCollection) HandleChain ¶
func (ec *ErrorCollection) HandleChain()
Handle the error queue one by one by those handler added How to add a handler> ec.AddHandler(Logger(),Panic(),SendEmail()) ... How to make handler routine dependent? ** When should do like this?** ** When you realize the handler might risk timing out or**
func LogEr() func(e error) { return func(e error) { go func(er error) { log.SetFlags(log.Llongfile | log.LstdFlags) log.Println(e.Error()) }(e) } }
func (*ErrorCollection) HandleInSeries ¶
func (ec *ErrorCollection) HandleInSeries(f ErrorHandlerWithContextInSeries)
this is a self design function to handle the inner errors collected via a single handler typed 'ErrorHandlerWithContextInSeries' DO not Use handler in series typed 'ErrorHandlerWithContextInSeries' together with basic typed 'ErrorHandler', because they share the error channel causing a single error could be handler only by one the them.
func (*ErrorCollection) IfErrorChanFull ¶
func (ec *ErrorCollection) IfErrorChanFull() bool
func (*ErrorCollection) Pop ¶
func (ec *ErrorCollection) Pop() error
Pop an error. The popped error is from queue' head. When use Pop(), it means the error has been dealed and deleted from the queue
func (*ErrorCollection) SafeLength ¶
func (ec *ErrorCollection) SafeLength() int
Return its error number
type ErrorHandler ¶
type ErrorHandler func(e error)