本文介绍镜像仓库 Go SDK 的使用方法以及代码示例。
go get github.com/volcengine/volcengine-go-sdk/volcengine go get github.com/volcengine/volcengine-go-sdk/volcengine/session
go get github.com/volcengine/volcengine-go-sdk/service/cr
每个接口都有一个对应的 Request 结构和一个 Response 结构。以下为创建命名空间接口 CreateNamespace 的 SDK 示例。
package main import ( "fmt" "github.com/volcengine/volcengine-go-sdk/service/cr" "github.com/volcengine/volcengine-go-sdk/volcengine" "github.com/volcengine/volcengine-go-sdk/volcengine/session" ) func main() { ak := "your_ak" sk := "your_sk" region := "your_region" //if use env Credentials //please //export volcengine_ACCESS_KEY=your_ak //export volcengine_SECRET_KEY=your_sk // and WithCredentials(credentials.NewEnvCredentials()) // Init client config := volcengine.NewConfig(). WithRegion(region). WithAkSk(ak, sk) //WithCredentials(credentials.NewEnvCredentials()). //WithLogLevel(volcengine.LogDebugWithHTTPBody) sess, _ := session.NewSession(config) svc := cr.New(sess) // Call OpenAPI cr CreateNamespace in := &cr.CreateNamespaceInput{ Name: volcengine.String("ns-1"), Registry: volcengine.String("registry-1"), } resp, err := svc.CreateNamespace(in) if err != nil { panic(err) } fmt.Printf("Response is %v", resp) }