Skip to content

Commit

Permalink
typo WarpContext -> WrapContext
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaomingqiang committed Dec 6, 2020
1 parent 18b893c commit 217fcd4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
15 changes: 12 additions & 3 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
7 changes: 7 additions & 0 deletions core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions sample/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sample/api/authen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand All @@ -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]",
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sample/api/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion sample/api/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion sample/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 217fcd4

Please sign in to comment.