本文为您介绍了安装 Go SDK 及其调用实例。
适用于Golang 1.13 及以上版本,可通过go version命令查看当前版本。
NewInstance
)需要指定region为ap-southeast-1
go get github.com/volcengine/volc-sdk-golang
package main import ( "context" "fmt" "github.com/volcengine/volc-sdk-golang/base" "github.com/volcengine/volc-sdk-golang/service/im" ) func main() { // 注意 AccessKey ID 和 AccessKey Secret的泄漏 // 无需重复初始化 只初始化一次即可 service := im.NewInstance() // 海外应用需要指定region为ap-southeast-1 //service := im.NewInstanceWithRegion("ap-southeast-1") service.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) var ( conversationName = "这是一个单聊示例" otherUserId int64 = 10002 ) body := &im.CreateConversationBody{ AppID: 000000, ConversationCoreInfo: im.CreateConversationBodyConversationCoreInfo{ ConversationType: 1, // 单聊 Name: &conversationName, }, OwnerUserID: 10001, // 群主,也就是发起单聊的人 OtherUserID: &otherUserId, // 单聊另一个UserId } resp, err := service.CreateConversation(context.Background(), body) if err != nil { fmt.Printf("error %v", err) } else { fmt.Printf("success %+v", resp) } }