errorCollection

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fmt

func Fmt() func(e error)

Fmt

func Logger

func Logger() func(e error)

Logger records error msg in log without modifying error queue.

func Panic

func Panic() func(e error)

Panic records the first error and recover. Panic aims to fix the panic cause error and ignore other errors unless you fix the error up

Types

type Context

type Context struct {
	M   *sync.RWMutex
	Map map[string]interface{}
}

func NewContext

func NewContext() *Context

func (*Context) Get

func (c *Context) Get(key string) interface{}

func (*Context) GetBool

func (c *Context) GetBool(key string) bool

func (*Context) GetInt

func (c *Context) GetInt(key string) int

func (*Context) GetString

func (c *Context) GetString(key string) string

func (*Context) Set

func (c *Context) Set(key string, value interface{})

type ErrorBox

type ErrorBox *queue.Queue

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 NewCollection

func NewCollection() *ErrorCollection

New a error collection

func (*ErrorCollection) Add

func (ec *ErrorCollection) Add(e error)

Add an error into collect

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) Clear

func (ec *ErrorCollection) Clear()

Clear errors in collection

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) Length

func (ec *ErrorCollection) Length() int

Return its error number

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)

type ErrorHandlerWithContextInSeries

type ErrorHandlerWithContextInSeries func(e error, ctx *Context) (next bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL