Skip to content

Commit

Permalink
docs: update hook docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lishuaiii committed Sep 1, 2021
1 parent c0e8dff commit 875d115
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ Or
Name string `bson:"name"`
Age int `bson:"age"`
}
func (u *User) BeforeInsert() error {
func (u *User) BeforeInsert(ctx context.Context) error {
fmt.Println("before insert called")
return nil
}
func (u *User) AfterInsert() error {
func (u *User) AfterInsert(ctx context.Context) error {
fmt.Println("after insert called")
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ go get github.com/qiniu/qmgo
Name string `bson:"name"`
Age int `bson:"age"`
}
func (u *User) BeforeInsert() error {
func (u *User) BeforeInsert(ctx context.Context) error {
fmt.Println("before insert called")
return nil
}
func (u *User) AfterInsert() error {
func (u *User) AfterInsert(ctx context.Context) error {
fmt.Println("after insert called")
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func TestMiddleware(t *testing.T) {
ast := require.New(t)
ctx := context.Background()
// not register
ast.NoError(Do("success", operator.BeforeInsert, ctx))
ast.NoError(Do(ctx, "success", operator.BeforeInsert))

// valid register
Register(callbackTest)
ast.NoError(Do("success", operator.BeforeInsert, ctx))
ast.Error(Do("failure", operator.BeforeUpsert, ctx))
ast.NoError(Do("failure", operator.BeforeUpdate, ctx, "success"))
ast.NoError(Do(ctx, "success", operator.BeforeInsert))
ast.Error(Do(ctx, "failure", operator.BeforeUpsert))
ast.NoError(Do(ctx, "failure", operator.BeforeUpdate, "success"))
}

func callbackTest(doc interface{}, opType operator.OpType, ctx context.Context, opts ...interface{}) error {
func callbackTest(ctx context.Context, doc interface{}, opType operator.OpType, opts ...interface{}) error {
if doc.(string) == "success" && opType == operator.BeforeInsert {
return nil
}
Expand Down

0 comments on commit 875d115

Please sign in to comment.