All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m33s
31 lines
491 B
Go
31 lines
491 B
Go
package exerr
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type ListenerOpt struct {
|
|
NoLog bool
|
|
}
|
|
|
|
type Listener = func(method Method, v *ExErr, opt ListenerOpt)
|
|
|
|
var listenerLock = sync.Mutex{}
|
|
var listener = make([]Listener, 0)
|
|
|
|
func RegisterListener(l Listener) {
|
|
listenerLock.Lock()
|
|
defer listenerLock.Unlock()
|
|
|
|
listener = append(listener, l)
|
|
}
|
|
|
|
func (ee *ExErr) CallListener(m Method, opt ListenerOpt) {
|
|
listenerLock.Lock()
|
|
defer listenerLock.Unlock()
|
|
|
|
for _, v := range listener {
|
|
v(m, ee, opt)
|
|
}
|
|
}
|