From 875d1154c613be91a81200f1ec99c755da2d6365 Mon Sep 17 00:00:00 2001 From: tq0fqeu Date: Thu, 2 Sep 2021 00:15:20 +0800 Subject: [PATCH] docs: update hook docs --- README.md | 4 ++-- README_ZH.md | 4 ++-- middleware/middleware_test.go | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2917c10..2ca0a1c 100644 --- a/README.md +++ b/README.md @@ -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 } diff --git a/README_ZH.md b/README_ZH.md index fd1097d..d1b5985 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -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 } diff --git a/middleware/middleware_test.go b/middleware/middleware_test.go index 987943f..7f096f5 100644 --- a/middleware/middleware_test.go +++ b/middleware/middleware_test.go @@ -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 }