Skip to content

Commit 6ea0e30

Browse files
author
baozhongyu.maple
committed
v2.7.26
1 parent 7ca85c6 commit 6ea0e30

7 files changed

Lines changed: 541 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# ChangeLog of TOS SDK for Go
2+
## 版本号 v2.7.26 日期:2025-11-13
3+
- 新增 SRAP 相关接口
4+
- 新增 Accelerator 相关接口
5+
6+
## 版本号 v2.7.25 日期:2025-11-06
7+
- 支持 SimpleQuery 和 SemanticQuery
8+
29
## 版本号 v2.7.24 日期:2025-10-04
310
- 优化自定义签名时间和 header 特性
411

tos/access_point.go

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package tos
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"net/http"
7+
)
8+
9+
func (cli *ClientV2) CreateAccessPoint(ctx context.Context, input *CreateAccessPointInput) (*CreateAccessPointOutput, error) {
10+
11+
if input == nil {
12+
return nil, InputIsNilClientError
13+
}
14+
data, contentMD5, err := marshalInput("CreateAccessPoint", input)
15+
if err != nil {
16+
return nil, err
17+
}
18+
19+
res, err := cli.newControlBuilder(input.AccountID).
20+
SetGeneric(input.GenericInput).
21+
WithHeader(HeaderContentMD5, contentMD5).
22+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
23+
RequestControl(ctx, http.MethodPut, bytes.NewReader(data), "/accesspoint/"+input.AccessPointName, cli.roundTripper(http.StatusOK))
24+
if err != nil {
25+
return nil, err
26+
}
27+
defer res.Close()
28+
output := CreateAccessPointOutput{RequestInfo: res.RequestInfo()}
29+
if err := marshalOutput(res, &output); err != nil {
30+
return nil, err
31+
}
32+
return &output, nil
33+
}
34+
35+
func (cli *ClientV2) GetAccessPoint(ctx context.Context, input *GetAccessPointInput) (*GetAccessPointOutput, error) {
36+
if input == nil {
37+
return nil, InputIsNilClientError
38+
}
39+
40+
res, err := cli.newControlBuilder(input.AccountID).
41+
SetGeneric(input.GenericInput).
42+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
43+
RequestControl(ctx, http.MethodGet, nil, "/accesspoint/"+input.AccessPointName, cli.roundTripper(http.StatusOK))
44+
if err != nil {
45+
return nil, err
46+
}
47+
defer res.Close()
48+
output := GetAccessPointOutput{RequestInfo: res.RequestInfo()}
49+
if err := marshalOutput(res, &output); err != nil {
50+
return nil, err
51+
}
52+
return &output, nil
53+
}
54+
55+
func (cli *ClientV2) ListAccessPoints(ctx context.Context, input *ListAccessPointsInput) (*ListAccessPointsOutput, error) {
56+
if input == nil {
57+
return nil, InputIsNilClientError
58+
}
59+
60+
res, err := cli.newControlBuilder(input.AccountID).
61+
SetGeneric(input.GenericInput).
62+
WithParams(*input).
63+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
64+
RequestControl(ctx, http.MethodGet, nil, "/accesspoint", cli.roundTripper(http.StatusOK))
65+
if err != nil {
66+
return nil, err
67+
}
68+
defer res.Close()
69+
output := ListAccessPointsOutput{RequestInfo: res.RequestInfo()}
70+
if err := marshalOutput(res, &output); err != nil {
71+
return nil, err
72+
}
73+
return &output, nil
74+
}
75+
76+
func (cli *ClientV2) DeleteAccessPoint(ctx context.Context, input *DeleteAccessPointInput) (*DeleteAccessPointOutput, error) {
77+
if input == nil {
78+
return nil, InputIsNilClientError
79+
}
80+
81+
res, err := cli.newControlBuilder(input.AccountID).
82+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
83+
RequestControl(ctx, http.MethodDelete, nil, "/accesspoint/"+input.AccessPointName, cli.roundTripper(http.StatusNoContent))
84+
if err != nil {
85+
return nil, err
86+
}
87+
defer res.Close()
88+
output := DeleteAccessPointOutput{RequestInfo: res.RequestInfo()}
89+
return &output, nil
90+
}
91+
92+
func (cli *ClientV2) ListBindAcceleratorForAccessPoint(ctx context.Context, input *ListBindAcceleratorForAccessPointInput) (*ListBindAcceleratorForAccessPointOutput, error) {
93+
if input == nil {
94+
return nil, InputIsNilClientError
95+
}
96+
97+
res, err := cli.newControlBuilder(input.AccountID).
98+
SetGeneric(input.GenericInput).
99+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
100+
RequestControl(ctx, http.MethodGet, nil, "/accesspoint/"+input.AccessPointName+"/accelerator", cli.roundTripper(http.StatusOK))
101+
if err != nil {
102+
return nil, err
103+
}
104+
defer res.Close()
105+
output := ListBindAcceleratorForAccessPointOutput{RequestInfo: res.RequestInfo()}
106+
if err := marshalOutput(res, &output); err != nil {
107+
return nil, err
108+
}
109+
return &output, nil
110+
}
111+
112+
func (cli *ClientV2) ListBindAccessPointForAccelerator(ctx context.Context, input *ListBindAccessPointForAcceleratorInput) (*ListBindAccessPointForAcceleratorOutput, error) {
113+
if input == nil {
114+
return nil, InputIsNilClientError
115+
}
116+
117+
res, err := cli.newControlBuilder(input.AccountID).
118+
SetGeneric(input.GenericInput).
119+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
120+
RequestControl(ctx, http.MethodGet, nil, "/accelerator/"+input.AcceleratorID+"/accesspoint", cli.roundTripper(http.StatusOK))
121+
if err != nil {
122+
return nil, err
123+
}
124+
defer res.Close()
125+
output := ListBindAccessPointForAcceleratorOutput{RequestInfo: res.RequestInfo()}
126+
if err := marshalOutput(res, &output); err != nil {
127+
return nil, err
128+
}
129+
return &output, nil
130+
}
131+
132+
func (cli *ClientV2) BindAcceleratorWithAccessPoint(ctx context.Context, input *BindAcceleratorWithAccessPointInput) (*BindAcceleratorWithAccessPointOutput, error) {
133+
134+
if input == nil {
135+
return nil, InputIsNilClientError
136+
}
137+
138+
res, err := cli.newControlBuilder(input.AccountID).
139+
SetGeneric(input.GenericInput).
140+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
141+
RequestControl(ctx, http.MethodPut, nil, "/accesspoint/"+input.AccessPointName+"/accelerator/"+input.AcceleratorID, cli.roundTripper(http.StatusOK))
142+
if err != nil {
143+
return nil, err
144+
}
145+
defer res.Close()
146+
output := BindAcceleratorWithAccessPointOutput{RequestInfo: res.RequestInfo()}
147+
return &output, nil
148+
}
149+
150+
func (cli *ClientV2) UnbindAcceleratorWithAccessPoint(ctx context.Context, input *UnbindAcceleratorWithAccessPointInput) (*UnbindAcceleratorWithAccessPointOutput, error) {
151+
if input == nil {
152+
return nil, InputIsNilClientError
153+
}
154+
res, err := cli.newControlBuilder(input.AccountID).
155+
SetGeneric(input.GenericInput).
156+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
157+
RequestControl(ctx, http.MethodDelete, nil, "/accesspoint/"+input.AccessPointName+"/accelerator/"+input.AcceleratorID, cli.roundTripper(http.StatusNoContent))
158+
if err != nil {
159+
return nil, err
160+
}
161+
defer res.Close()
162+
output := UnbindAcceleratorWithAccessPointOutput{RequestInfo: res.RequestInfo()}
163+
return &output, nil
164+
}

tos/consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
const (
99
// Version tos-go-sdk version
10-
Version = "v2.7.24"
10+
Version = "v2.7.26"
1111
)
1212

1313
const TempFileSuffix = ".temp"

tos/enum/enum.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,52 @@ const (
263263
MRAPStatusDELETING MRAPStatusType = "DELETING"
264264
MRAPStatusFAILED MRAPStatusType = "FAILED"
265265
)
266+
267+
type QueryOrderType string
268+
269+
const (
270+
QueryOrderDesc QueryOrderType = "desc"
271+
QueryOrderAsc QueryOrderType = "asc"
272+
)
273+
274+
type QueryOperationType string
275+
276+
const (
277+
QueryOperationNot QueryOperationType = "not"
278+
QueryOperationOr QueryOperationType = "or"
279+
QueryOperationAnd QueryOperationType = "and"
280+
QueryOperationLt QueryOperationType = "lt"
281+
QueryOperationLte QueryOperationType = "lte"
282+
QueryOperationGt QueryOperationType = "gt"
283+
QueryOperationGte QueryOperationType = "gte"
284+
QueryOperationEq QueryOperationType = "eq"
285+
QueryOperationExist QueryOperationType = "exist"
286+
QueryOperationPrefix QueryOperationType = "prefix"
287+
QueryOperationMatchPhrase QueryOperationType = "match-phrase"
288+
)
289+
290+
type AggregationOperationType string
291+
292+
const (
293+
AggregationOperationMin AggregationOperationType = "min"
294+
AggregationOperationMax AggregationOperationType = "max"
295+
AggregationOperationAverage AggregationOperationType = "average"
296+
AggregationOperationSum AggregationOperationType = "sum"
297+
AggregationOperationCount AggregationOperationType = "count"
298+
AggregationOperationDistinct AggregationOperationType = "distinct"
299+
AggregationOperationGroup AggregationOperationType = "group"
300+
)
301+
302+
type SemanticQueryType string
303+
304+
const (
305+
SemanticQueryTypeText SemanticQueryType = "text"
306+
SemanticQueryTypeImage SemanticQueryType = "image"
307+
)
308+
309+
type NetworkOriginType string
310+
311+
const (
312+
NetworkOriginVpc NetworkOriginType = "vpc"
313+
NetworkOriginInternet NetworkOriginType = "internet"
314+
)

tos/query.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package tos
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"net/http"
7+
)
8+
9+
func (cli *ClientV2) SimpleQuery(ctx context.Context, input *SimpleQueryInput) (*SimpleQueryOutput, error) {
10+
if input == nil {
11+
return nil, InputIsNilClientError
12+
}
13+
data, contentMD5, err := marshalInput("SimpleQuery", input)
14+
if err != nil {
15+
return nil, err
16+
}
17+
res, err := cli.newControlBuilder(input.AccountID).
18+
SetGeneric(input.GenericInput).
19+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
20+
WithQuery("mode", "SimpleQuery").
21+
WithHeader(HeaderContentMD5, contentMD5).
22+
RequestControl(ctx, http.MethodPost, bytes.NewReader(data), "/datasetquery", cli.roundTripper(http.StatusOK))
23+
if err != nil {
24+
return nil, err
25+
}
26+
defer res.Close()
27+
output := SimpleQueryOutput{RequestInfo: res.RequestInfo()}
28+
if err = marshalOutput(res, &output); err != nil {
29+
return nil, err
30+
}
31+
return &output, nil
32+
}
33+
34+
func (cli *ClientV2) SemanticQuery(ctx context.Context, input *SemanticQueryInput) (*SemanticQueryOutput, error) {
35+
if input == nil {
36+
return nil, InputIsNilClientError
37+
}
38+
data, contentMD5, err := marshalInput("SemanticQuery", input)
39+
if err != nil {
40+
return nil, err
41+
}
42+
res, err := cli.newControlBuilder(input.AccountID).
43+
SetGeneric(input.GenericInput).
44+
WithRetry(OnRetryFromStart, StatusCodeClassifier{}).
45+
WithQuery("mode", "SemanticQuery").
46+
WithHeader(HeaderContentMD5, contentMD5).
47+
RequestControl(ctx, http.MethodPost, bytes.NewReader(data), "/datasetquery", cli.roundTripper(http.StatusOK))
48+
if err != nil {
49+
return nil, err
50+
}
51+
defer res.Close()
52+
output := SemanticQueryOutput{RequestInfo: res.RequestInfo()}
53+
if err = marshalOutput(res, &output); err != nil {
54+
return nil, err
55+
}
56+
return &output, nil
57+
}

tos/tests/access_point_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package tests
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
9+
"github.com/volcengine/ve-tos-golang-sdk/v2/tos/enum"
10+
)
11+
12+
func TestAccessPoint(t *testing.T) {
13+
var (
14+
env = newTestEnv(t)
15+
bucket = generateBucketName("access-point")
16+
client = env.prepareClient(bucket)
17+
)
18+
defer func() {
19+
cleanBucket(t, client, bucket)
20+
}()
21+
ctx := context.Background()
22+
apName := generateBucketName("ap")
23+
24+
resp, err := client.CreateAccessPoint(ctx, &tos.CreateAccessPointInput{AccountID: env.accountId, BucketAccountID: env.accountId, AccessPointName: apName, Bucket: bucket, NetworkOrigin: enum.NetworkOriginInternet})
25+
require.NoError(t, err)
26+
require.NotEmpty(t, resp)
27+
require.NotEqual(t, resp.Alias, "")
28+
require.NotEqual(t, resp.AccessPointTrn, "")
29+
30+
getResp, err := client.GetAccessPoint(ctx, &tos.GetAccessPointInput{AccountID: env.accountId, AccessPointName: apName})
31+
require.NoError(t, err)
32+
require.NotEmpty(t, getResp)
33+
34+
listResp, err := client.ListAccessPoints(ctx, &tos.ListAccessPointsInput{
35+
Bucket: bucket,
36+
AccountID: env.accountId,
37+
})
38+
require.NoError(t, err)
39+
require.NotEmpty(t, listResp)
40+
require.Equal(t, len(listResp.AccessPoints), 1)
41+
42+
listAccResp, err := client.ListBindAcceleratorForAccessPoint(ctx, &tos.ListBindAcceleratorForAccessPointInput{
43+
AccountID: env.accountId,
44+
AccessPointName: apName,
45+
})
46+
require.NoError(t, err)
47+
require.NotEmpty(t, listAccResp)
48+
49+
deleteResp, err := client.DeleteAccessPoint(ctx, &tos.DeleteAccessPointInput{AccountID: env.accountId, AccessPointName: apName})
50+
require.NoError(t, err)
51+
require.NotEmpty(t, deleteResp)
52+
}

0 commit comments

Comments
 (0)