micro/options/hooks.go
Vasiliy Tolstov ebd8ddf05b move to v4
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-04-11 22:21:25 +03:00

32 lines
641 B
Go

package options // import "go.unistack.org/micro/v4/options"
// Hook func interface
type Hook interface{}
// Hooks func slice
type Hooks []Hook
// Append is used to add hooks
func (hs *Hooks) Append(h ...Hook) {
*hs = append(*hs, h...)
}
// Replace is used to set hooks
func (hs *Hooks) Replace(h ...Hook) {
*hs = h
}
// EachNext is used to itearate over hooks forward
func (hs *Hooks) EachNext(fn func(Hook)) {
for idx := 0; idx < len(*hs); idx++ {
fn((*hs)[idx])
}
}
// EachPrev is used to iterate over hooks backward
func (hs *Hooks) EachPrev(fn func(Hook)) {
for idx := len(*hs) - 1; idx >= 0; idx-- {
fn((*hs)[idx])
}
}