环境要求:Go 环境版本必须不低于 1.15
默认获取最新版本,可指定版本号
go get github.com/volcengine/cdp-openapi-sdk-go@version
具体源码及版本号见仓库 GitHub仓库地址(源码更新会有延迟)
access_key:BDxxxxx secret_key:xxxxx domain:域名 account:绑定的用户名
access_key,secret_key,domain 获取方式见接入须知
注意:使用OpenApi时,CDP资源权限与此绑定账户权限相关联,请勿越权访问
var accessKeyId = "BDxxxx" var accessKeySecret = "xxxx" var account = "account_name" var basePath = "<域名>/open_platform/openapi" func main() { httpClient := http.Client{} cfg := cdpOpenApiSdk.Configuration{ AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, BasePath: basePath, HTTPClient: &httpClient, Account: account, } client, err := cdpOpenApiSdk.NewAPIClient(&cfg)
var accessKeyId = "BDxxxx" var accessKeySecret = "xxxx" var basePath = "<域名>/open_platform/openapi" func main() { httpClient := http.Client{} cfg := cdpOpenApiSdk.Configuration{ AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, BasePath: basePath, HTTPClient: &httpClient, } client, err := cdpOpenApiSdk.NewAPIClient(&cfg)
文档中示例代码仅供参考
opts := SegmentationApiLegacyGetSegmentListOpts{Current: optional.NewInt32(1), PageSize: optional.NewInt32(20)} responseBody, httpRespose, err := client.SegmentationApi.LegacyGetSegmentList(context.Background(), 1, &opts)
tenantId := 1 segId : =123 responseBody, httpRespose, err := client.SegmentationApi.LegacyGetSegment(context.Background(), tenantId, segId)
1.使用STS方式时,请保存 ApiClient,构造器会自动获取Token并保存,不建议每次请求都新构建ApiClient(每次新构建都会触发一次获取Token操作)
2.SDK版本与CDP版本相对应,CDP版本号对应SDK前两位版本号,例如CDP版本1.22,则SDK对应版本为1.22.X
其中X为SDK对应的patch,建议使用相匹配的版本以获得最新功能和最佳使用体验