使用火山引擎 Go SDK 进行各类操作前,您需要安装 Go SDK。本文介绍 Go SDK 的安装方法。
请参考 Go 官网下载和安装 Go 编译运行环境。
go help gopath
。go version
检查当前 Go 的版本信息。go get -u github.com/volcengine/volcengine-go-sdk
require github.com/volcengine/volcengine-go-sdk v1.0.91
Volcengine Go SDK 支持通过 Session 的方式来初始化客户端。通过 Session 方式创建的 客户端,底层会实现 HTTP/HTTPS 资源(连接或请求)的复用。当需要初始化多个客户端进行操作时,通过 Session 方式创建可以提升客户端的性能。本文介绍如何通过 Session 的方式来初始化客户端。
初始化客户端的示例代码如下:
package main import ( "github.com/volcengine/volcengine-go-sdk/service/kafka" "github.com/volcengine/volcengine-go-sdk/volcengine" "github.com/volcengine/volcengine-go-sdk/volcengine/credentials" "github.com/volcengine/volcengine-go-sdk/volcengine/session" ) func main() { ak, sk, region := "Your AK", "Your SK", "cn-beijing" config := volcengine.NewConfig(). WithRegion(region). WithCredentials(credentials.NewStaticCredentials(ak, sk, "")) sess, err := session.NewSession(config) if err != nil { panic(err) } svc := kafka.New(sess) }