mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Make callback type
This commit is contained in:
@@ -4,4 +4,20 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type OnDecode func(ctx context.Context, iter interface{}) (err error)
|
||||
type Callback func(ctx context.Context, iter interface{}) (err error)
|
||||
type Callbacks []Callback
|
||||
|
||||
type OnDecode Callback
|
||||
|
||||
// Invoke callbacks sequence
|
||||
func (c Callbacks) Invoke(ctx context.Context, iter interface{}) (err error) {
|
||||
|
||||
for _, cb := range c {
|
||||
err = cb(ctx, iter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func applyCallbacks(q *Query, f interface{}) (ok bool) {
|
||||
|
||||
switch cb := f.(type) {
|
||||
case OnDecode:
|
||||
q.ondecode = append(q.ondecode, cb)
|
||||
q.ondecode = append(q.ondecode, Callback(cb))
|
||||
ok = true
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ type Query struct {
|
||||
sorter Sorter
|
||||
skipper Skipper
|
||||
preloader Preloader
|
||||
ondecode []OnDecode
|
||||
ondecode Callbacks
|
||||
}
|
||||
|
||||
// And function pushes the elem query to the $and array of the query
|
||||
@@ -77,7 +77,7 @@ func (q *Query) Preloader() (ok bool, preloads []string) {
|
||||
}
|
||||
|
||||
// OnDecode callback is called after the mongo decode function
|
||||
func (q *Query) OnDecode() (callbacks []OnDecode) {
|
||||
func (q *Query) OnDecode() (callbacks Callbacks) {
|
||||
return q.ondecode
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user