Skip to content

Commit cc5fc79

Browse files
auto: apply newest APITable commit
1 parent c125d23 commit cc5fc79

File tree

18 files changed

+511
-223
lines changed

18 files changed

+511
-223
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
MIT License
33

4-
Copyright (c) 2021 VIKADATA
4+
Copyright (c) 2021 APITABLE
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() {
4545
}
4646
request.Fields = common.StringPtrs([]string{"number_field"})
4747
records, err := datasheet.DescribeAllRecords(request)
48-
if _, ok := err.(*vkerror.VikaSDKError); ok {
48+
if _, ok := err.(*vkerror.SDKError); ok {
4949
fmt.Printf("An API error has returned: %s", err)
5050
return
5151
}
@@ -57,7 +57,7 @@ func main() {
5757
fmt.Printf("%#v\n", records)
5858
// 分页获取数据
5959
page, err := datasheet.DescribeRecords(request)
60-
if _, ok := err.(*vkerror.VikaSDKError); ok {
60+
if _, ok := err.(*vkerror.SDKError); ok {
6161
fmt.Printf("An API error has returned: %s", err)
6262
return
6363
}
@@ -77,7 +77,7 @@ func main() {
7777
},
7878
}
7979
createRecords, err := datasheet.CreateRecords(createRequest)
80-
if _, ok := err.(*vkerror.VikaSDKError); ok {
80+
if _, ok := err.(*vkerror.SDKError); ok {
8181
fmt.Printf("An API error has returned: %s", err)
8282
return
8383
}
@@ -98,7 +98,7 @@ func main() {
9898
},
9999
}
100100
modifyRecords, err := datasheet.ModifyRecords(modifyRequest)
101-
if _, ok := err.(*vkerror.VikaSDKError); ok {
101+
if _, ok := err.(*vkerror.SDKError); ok {
102102
fmt.Printf("An API error has returned: %s", err)
103103
return
104104
}
@@ -112,7 +112,7 @@ func main() {
112112
deleteRequest := vika.NewDeleteRecordsRequest()
113113
request.RecordIds = common.StringPtrs([]string{"recordId1", "recordId2"})
114114
err = datasheet.DeleteRecords(deleteRequest)
115-
if _, ok := err.(*vkerror.VikaSDKError); ok {
115+
if _, ok := err.(*vkerror.SDKError); ok {
116116
fmt.Printf("An API error has returned: %s", err)
117117
return
118118
}
@@ -125,7 +125,7 @@ func main() {
125125
uploadRequest := vika.NewUploadRequest()
126126
request.FilePath = "image.png"
127127
attachment, err := datasheet.UploadFile(request)
128-
if _, ok := err.(*vkerror.VikaSDKError); ok {
128+
if _, ok := err.(*vkerror.SDKError); ok {
129129
fmt.Printf("An API error has returned: %s", err)
130130
return
131131
}

examples/datasheet/record.go

+21-19
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,44 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/vikadata/vika.go/lib/common"
7-
vkerror "github.com/vikadata/vika.go/lib/common/error"
8-
"github.com/vikadata/vika.go/lib/common/profile"
9-
vika "github.com/vikadata/vika.go/lib/datasheet"
6+
"github.com/apitable/apitable-sdks/apitable.go/lib/common"
7+
aterror "github.com/apitable/apitable-sdks/apitable.go/lib/common/error"
8+
"github.com/apitable/apitable-sdks/apitable.go/lib/common/profile"
9+
apitable "github.com/apitable/apitable-sdks/apitable.go/lib/datasheet"
1010
"os"
1111
)
1212

1313
func main() {
14-
// 必要步骤:
15-
// 实例化一个认证对象,入参需要传入vika开发者token。
16-
// 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这个值。
17-
// 你也可以直接在代码中写死token,但是小心不要将代码复制、上传或者分享给他人,
18-
// 以免泄露token危及你的财产安全。
14+
// necessary steps:
15+
// Instantiating an authentication object, the input parameter requires the apitable developer token.
16+
// Here is the way to read from environment variables.
17+
// This value needs to be set first in the environment variable.
18+
// You can also write dead token directly in the code.
19+
// But be careful not to copy, upload or share the code with others,
20+
// so as not to disclose the token and endanger the safety of your property.
1921
credential := common.NewCredential(
20-
os.Getenv("VIKA_TOKEN"),
22+
os.Getenv("APITABLE_TOKEN"),
2123
)
2224
cpf := profile.NewClientProfile()
23-
// 上传图片
25+
// upload pictures
2426
attachment1, err := uploadImage(credential, cpf)
25-
if _, ok := err.(*vkerror.VikaSDKError); ok {
27+
if _, ok := err.(*aterror.SDKError); ok {
2628
fmt.Printf("uploadImage:An API error has returned: %s", err)
2729
return
2830
}
29-
// 非SDK异常,直接失败。实际代码中可以加入其他的处理。
31+
// Non-SDK exception, direct failure. Other processing can be added to the actual code.
3032
if err != nil {
3133
panic(err)
3234
}
3335
json1, _ := json.Marshal(attachment1)
34-
fmt.Printf("上传图片结果:%s\n", json1)
36+
fmt.Printf("Upload picture results:%s\n", json1)
3537
}
3638

37-
func uploadImage(credential *common.Credential, cpf *profile.ClientProfile) (*vika.Attachment, error) {
39+
func uploadImage(credential *common.Credential, cpf *profile.ClientProfile) (*apitable.Attachment, error) {
3840
cpf.Upload = true
39-
datasheet, _ := vika.NewDatasheet(credential, os.Getenv("VIKA_DATASHEET_ID"), cpf)
40-
request := vika.NewUploadRequest()
41-
// 如果不设置Domain使用默认的域名
42-
request.FilePath = "图片完整路径"
41+
datasheet, _ := apitable.NewDatasheet(credential, os.Getenv("APITABLE_DATASHEET_ID"), cpf)
42+
request := apitable.NewUploadRequest()
43+
// If you do not set domain, use the default domain name.
44+
request.FilePath = "picture full path"
4345
return datasheet.UploadFile(request)
4446
}

examples/datasheet/scf/README.md

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
1-
# Vika golang SDK Example for SCF
1+
# Apitable golang SDK Example for SCF
22

3-
[Vika](https://vika.cn) Golang SDK 结合腾讯云函数的一个应用。
4-
## 功能描述
5-
从vika表读取数据,进行批量删除。每次读取100条记录删除
3+
[Apitable](https://apitable.com) Golang SDK, an application of the combined Tencent Serverless Cloud Function.
64

7-
## 简单上手
8-
### 环境要求
5+
## Functional description
6+
7+
Read data from the apitable and delete it in batches. Read up to 100 records at a time.
8+
9+
## Quickstart
10+
11+
### environmental requirements
912

1013
go 1.15 +
1114

12-
### 1. 依赖安装
15+
### 1. install dependency
1316

1417
```shell
1518
go mod tidy
1619
```
17-
### 2. 编译打包
18-
* 在 Linux 或 MacOS 的终端通过如下方法完成编译及打包:
20+
21+
### 2. compile and package
22+
23+
* The Linux or MacOS terminal completes compilation and packaging through the following methods:
1924

2025
```shell
2126
GOOS=linux GOARCH=amd64 go build -o main main.go
2227

2328
zip main.zip main
2429
```
2530

26-
* 在 Windows 下打包:
27-
由于up主没有在windows系统进行测试,所以请参考腾讯云函数[Golang部署文档](https://cloud.tencent.com/document/product/583/67385)
31+
* pack under windows:
32+
please refer to Tencent Serverless Cloud Function [Golang](https://cloud.tencent.com/document/product/583/67385)
2833

29-
### 3. 上传打包好的zip包
34+
### 3. upload the packaged zip package
3035
![img.png](img.png)
3136

32-
### 4. 添加环境变量
33-
请在云函数添加如下环境变量
37+
### 4. add environment variable
38+
39+
Please add the following environment variables to Serverless Cloud Function.
3440

3541
```YAML
36-
# vika数表ID
3742
DATASHEET_ID
3843

39-
# 需要排序的字段
4044
SORT_FIELD_NAME
4145

42-
# 视图字段
4346
VIEW_ID
4447

45-
# api token 访问维格表的工作台,点击左下角的个人头像,进入「用户中心 > 开发者配置」。点击生成Token(首次使用需要绑定邮箱)。
46-
VIKA_TOKEN=
48+
# Visit the workbench of apitable, click on the personal avatar in the lower left corner, and enter [My Setting > Developer].
49+
# click generate token (binding email required for first use).
50+
APITABLE_TOKEN=
4751
```
4852

4953
## todo

examples/datasheet/scf/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module example/datasheet/scf
22

33
go 1.17
44

5-
require github.com/vikadata/vika.go v0.0.3
5+
require github.com/apitable/apitable-sdks/apitable.go v0.0.5
66

77
require (
88
github.com/h2non/filetype v1.1.0 // indirect

examples/datasheet/scf/main.go

+22-20
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ package main
22

33
import (
44
"fmt"
5+
"github.com/apitable/apitable-sdks/apitable.go/lib/common"
6+
"github.com/apitable/apitable-sdks/apitable.go/lib/common/profile"
7+
apitable "github.com/apitable/apitable-sdks/apitable.go/lib/datasheet"
58
"github.com/tencentyun/scf-go-lib/cloudfunction"
6-
"github.com/vikadata/vika.go/lib/common"
7-
"github.com/vikadata/vika.go/lib/common/profile"
8-
vika "github.com/vikadata/vika.go/lib/datasheet"
99
"math"
1010
"os"
1111
)
1212

13-
func getRecords(credential *common.Credential, cpf *profile.ClientProfile) []*vika.Record {
14-
datasheet, _ := vika.NewDatasheet(credential, os.Getenv("DATASHEET_ID"), cpf)
15-
request := vika.NewDescribeRecordRequest()
16-
request.Sort = []*vika.Sort{
13+
func getRecords(credential *common.Credential, cpf *profile.ClientProfile) []*apitable.Record {
14+
datasheet, _ := apitable.NewDatasheet(credential, os.Getenv("DATASHEET_ID"), cpf)
15+
request := apitable.NewDescribeRecordRequest()
16+
request.Sort = []*apitable.Sort{
1717
{
1818
Field: common.StringPtr(os.Getenv("SORT_FIELD_NAME")),
1919
Order: common.StringPtr("asc"),
@@ -25,42 +25,44 @@ func getRecords(credential *common.Credential, cpf *profile.ClientProfile) []*vi
2525
request.PageSize = common.Int64Ptr(100)
2626
records, err := datasheet.DescribeRecords(request)
2727
if err != nil {
28-
fmt.Println("获取记录失败")
28+
fmt.Println("Get records error.")
2929
panic(err)
3030
}
3131
return records.Records
3232
}
3333

3434
func hello() (string, error) {
35-
// 必要步骤:
36-
// 实例化一个认证对象,入参需要传入vika开发者token。
37-
// 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这个值。
38-
// 你也可以直接在代码中写死token,但是小心不要将代码复制、上传或者分享给他人,
39-
// 以免泄露token危及你的财产安全。
35+
// necessary steps:
36+
// Instantiating an authentication object, the input parameter requires the apitable developer token.
37+
// Here is the way to read from environment variables.
38+
// This value needs to be set first in the environment variable.
39+
// You can also write dead token directly in the code.
40+
// But be careful not to copy, upload or share the code with others,
41+
// so as not to disclose the token and endanger the safety of your property.
4042
credential := common.NewCredential(
41-
os.Getenv("VIKA_TOKEN"),
43+
os.Getenv("APITABLE_TOKEN"),
4244
)
43-
fmt.Println("开始执行")
45+
fmt.Println("Start execution")
4446
cpf := profile.NewClientProfile()
4547
records := getRecords(credential, cpf)
4648
var recordIds []*string
4749
for i := range records {
4850
recordIds = append(recordIds, records[i].RecordId)
4951
}
50-
fmt.Println("获取到的记录条数:", len(recordIds))
52+
fmt.Println("Number of records obtained: ", len(recordIds))
5153
return deleteRecords(credential, cpf, recordIds)
5254
}
5355

5456
func deleteRecords(credential *common.Credential, cpf *profile.ClientProfile, recordIds []*string) (string, error) {
55-
datasheet, _ := vika.NewDatasheet(credential, os.Getenv("DATASHEET_ID"), cpf)
56-
request := vika.NewDeleteRecordsRequest()
57+
datasheet, _ := apitable.NewDatasheet(credential, os.Getenv("DATASHEET_ID"), cpf)
58+
request := apitable.NewDeleteRecordsRequest()
5759
for i := 0; i < int(math.Ceil(float64(len(recordIds)/10))); i++ {
5860
request.RecordIds = recordIds[i*10 : (i+1)*10]
5961
err := datasheet.DeleteRecords(request)
6062
if err != nil {
61-
fmt.Println("删除失败", i)
63+
fmt.Println("Delete failed", i)
6264
}
63-
fmt.Println("删除成功", i)
65+
fmt.Println("Delete successful", i)
6466
}
6567
return "", nil
6668
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/vikadata/vika.go
1+
module github.com/apitable/apitable-sdks/apitable.go
22

33
go 1.15
44

0 commit comments

Comments
 (0)