From 217fcd4c290dcdf464eec7d4b9a1a8a31edaec7a Mon Sep 17 00:00:00 2001 From: zhaomingqiang Date: Sun, 6 Dec 2020 18:38:34 +0800 Subject: [PATCH] typo WarpContext -> WrapContext --- README.md | 14 ++++++++++++-- README.zh.md | 15 ++++++++++++--- core/context.go | 7 +++++++ sample/api/api.go | 6 +++--- sample/api/authen.go | 6 +++--- sample/api/contact.go | 4 ++-- sample/api/image.go | 2 +- sample/config/config.go | 2 +- 8 files changed, 41 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1b969ed0..3a77cf89 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ $ go get -u github.com/larksuite/oapi-sdk-go // Create CoreContext(*core.Context) for API requests, Event callbacks, Card callbacks, etc., as function parameters // core.Context implements the context.Context interface - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) // Get the RequestID(string) of API requests, Event callbacks, and Card callbacks, used for problem feedback, open platform query related logs, you can quickly locate the problem requestID := coreCtx.GetRequestID() // Get response to API request Status code(int) @@ -102,7 +102,17 @@ $ go get -u github.com/larksuite/oapi-sdk-go // request.SetNotDataField(), set whether the response does not have a `data` field, business interfaces all have `data `Field, so you don’t need to set // request.SetTenantKey("TenantKey"), as an `app store application`, it means using `tenant_access_token` to access the API, you need to set // request.SetUserAccessToken("UserAccessToken"), which means using` user_access_token` To access the API, you need to set - req := request.NewRequest2(httpPath:string, httpMethod:string, accessTokenType:AccessTokenType ,input:interface, output:interface ,... optFns : OptFn [))) + // req := request.NewRequest2(httpPath:string, httpMethod:string, accessTokenType:AccessTokenType, input:interface, output:interface, ... optFns:OptFn [))) + // Example: + body := map[string]interface{}{ + "open_id": "[open_id]", + "msg_type": "text", + "content": map[string]interface{}{ + "text": "test", + }, + } + ret := make(map[string]interface{}) + req := request.NewRequest2("message/v4/send", "POST", request.AccessTokenTypeTenant, body, &ret) coreCtx := core.WarpContext(context.Background()) err := api.Send(coreCtx, conf, req) fmt.Println(coreCtx.GetRequestID()) diff --git a/README.zh.md b/README.zh.md index 3e6d07c2..16492792 100644 --- a/README.zh.md +++ b/README.zh.md @@ -62,7 +62,7 @@ $ go get -u github.com/larksuite/oapi-sdk-go // 创建CoreContext(*core.Context),用于API请求、Event回调、Card回调等,作为函数的参数 // core.Context实现了context.Context接口 - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) // 获取 API请求、Event回调、Card回调的RequestID(string),用于问题反馈时,开放平台查询相关日志,可以快速的定位问题 requestID := coreCtx.GetRequestID() // 获取 API请求的响应状态码(int) @@ -107,8 +107,17 @@ $ go get -u github.com/larksuite/oapi-sdk-go // request.SetNotDataField(),设置响应的是否 没有`data`字段,业务接口都是有`data`字段,所以不需要设置 // request.SetTenantKey("TenantKey"),以`应用商店应用`身份,表示使用`tenant_access_token`访问API,需要设置 // request.SetUserAccessToken("UserAccessToken"),表示使用`user_access_token`访问API,需要设置 - req := request.NewRequest2(httpPath: string, httpMethod: string, accessTokenType: AccessTokenType, input: interface, output: interface, ...optFns: OptFn[])) - coreCtx := core.WarpContext(context.Background()) + // req := request.NewRequest2(httpPath:string, httpMethod:string, accessTokenType:AccessTokenType, input:interface, output:interface, ... optFns:OptFn [))) + // Example: + body := map[string]interface{}{ + "open_id": "[open_id]", + "msg_type": "text", + "content": map[string]interface{}{ + "text": "test", + }, + } + ret := make(map[string]interface{}) + req := request.NewRequest2("message/v4/send", "POST", request.AccessTokenTypeTenant, body, &ret)coreCtx := core.WarpContext(context.Background()) err := api.Send(coreCtx, conf, req) fmt.Println(coreCtx.GetRequestID()) fmt.Println(coreCtx.GetHTTPStatusCode()) diff --git a/core/context.go b/core/context.go index 2713f50c..942cfcc2 100644 --- a/core/context.go +++ b/core/context.go @@ -13,12 +13,19 @@ type Context struct { m map[string]interface{} } +// Deprecated, please use `WrapContext` func WarpContext(c context.Context) *Context { return &Context{ c: c, } } +func WrapContext(c context.Context) *Context { + return &Context{ + c: c, + } +} + func (c *Context) SetRequestID(logID, requestID string) { if logID != "" { c.Set(constants.HTTPHeaderKeyRequestID, logID) diff --git a/sample/api/api.go b/sample/api/api.go index 20a7c4bd..1a0a31ed 100644 --- a/sample/api/api.go +++ b/sample/api/api.go @@ -24,7 +24,7 @@ func main() { // send message func testSendMessage() { - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) body := map[string]interface{}{ "open_id": "[open_id]", "msg_type": "text", @@ -56,7 +56,7 @@ type UploadImage struct { // upload image func testUploadFile() { - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) bs, err := ioutil.ReadFile("test.png") if err != nil { fmt.Println(err) @@ -91,7 +91,7 @@ func testUploadFile() { // download image func testDownloadFile() { - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) ret := &bytes.Buffer{} /* // stream download: ret implement io.Writer diff --git a/sample/api/authen.go b/sample/api/authen.go index df7317b3..4675ccd8 100644 --- a/sample/api/authen.go +++ b/sample/api/authen.go @@ -20,7 +20,7 @@ func main() { func testAccessToken() { ctx := context.Background() - coreCtx := core.WarpContext(ctx) + coreCtx := core.WrapContext(ctx) body := &authen.AuthenAccessTokenReqBody{ GrantType: "authorization_code", Code: "[code]", @@ -42,7 +42,7 @@ func testAccessToken() { func testFlushAccessToken() { ctx := context.Background() - coreCtx := core.WarpContext(ctx) + coreCtx := core.WrapContext(ctx) body := &authen.AuthenRefreshAccessTokenReqBody{ GrantType: "refresh_token", RefreshToken: "[refresh_token]", @@ -64,7 +64,7 @@ func testFlushAccessToken() { func testUserInfo() { ctx := context.Background() - coreCtx := core.WarpContext(ctx) + coreCtx := core.WrapContext(ctx) reqCall := authenService.Authens.UserInfo(coreCtx, request.SetUserAccessToken("[user_access_token]")) result, err := reqCall.Do() diff --git a/sample/api/contact.go b/sample/api/contact.go index 4d677f42..c72793fc 100644 --- a/sample/api/contact.go +++ b/sample/api/contact.go @@ -18,7 +18,7 @@ func main() { } func testUserServiceList() { - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) reqCall := contactService.Users.List(coreCtx) reqCall.SetDepartmentIdType("open_id") reqCall.SetPageSize(20) @@ -37,7 +37,7 @@ func testUserServiceList() { } func testDepartmentServiceUpdate() { - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) updateBody := &contact.Department{ Name: "xxxxx", ParentDepartmentId: "od_xxxxxx", diff --git a/sample/api/image.go b/sample/api/image.go index dccc0da4..0e44b5b5 100644 --- a/sample/api/image.go +++ b/sample/api/image.go @@ -19,7 +19,7 @@ func main() { func testUpload() { ctx := context.Background() - coreCtx := core.WarpContext(ctx) + coreCtx := core.WrapContext(ctx) reqCall := imageService.Images.Put(coreCtx, request.SetTenantKey("[tenant_key]")) reqCall.SetImageType("message") f, err := os.Open("test.png") diff --git a/sample/config/config.go b/sample/config/config.go index fd0ad3c1..207deca3 100644 --- a/sample/config/config.go +++ b/sample/config/config.go @@ -14,7 +14,7 @@ import ( func GetConfig(domain constants.Domain, appSettings *config.AppSettings, level log.Level) *config.Config { logger := Logrus{} store := NewRedisStore() - coreCtx := core.WarpContext(context.Background()) + coreCtx := core.WrapContext(context.Background()) coreCtx.GetHTTPStatusCode() return config.NewConfig(constants.DomainLarkSuite, appSettings, logger, level, store) }