更新时间:2025-07-18 gmt 08:00

go sdk使用范例-j9九游会登录

以为例,提供封装后的sdk。为了保证您成功使用以下示例代码,您需要先添加对应语言的sdk依赖。

表1 go sdk信息说明

sdk信息

说明

安装

go get -u github.com/huaweicloud/huaweicloud-sdk-go-v3

相关链接

sdk的请求参数、响应参数、请求示例和响应示例与对应的api一致,具体参数和示例说明请参见同步执行函数接口。

sdk调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
packagemain
import(
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
functiongraph"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model"
region"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/region"
)
funcmain(){
// the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
// in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
ak:=os.getenv("cloud_sdk_ak")
sk:=os.getenv("cloud_sdk_sk")
auth:=basic.newcredentialsbuilder().
withak(ak).
withsk(sk).
build()
client:=functiongraph.newfunctiongraphclient(
functiongraph.functiongraphclientbuilder().
withregion(region.valueof("")).
withcredential(auth).
build())
request:=&model.invokefunctionrequest{}
varlistinvokefunctionrequestbodybody=map[string]interface{}{
"k":"v"
}
request.body=listinvokefunctionrequestbodybody
responseerr:=client.invokefunction(request)
iferr==nil{
fmt.printf("% v\n"response)
}else{
fmt.println(err)
}
}

ak/sk、region(endpoint)、project_id(项目id)的获取请参见ak/sk签名认证操作指导

func_name、version在函数界面上获取。

xcffrequestversionrequest:返回体格式,取值v0,v1。v0:默认返回文本格式;v1:默认返回json格式,sdk需要使用此值。

相关文档

网站地图