go - 如何在 Golang 中编写客户端代码来调用 createSnapshot softlayer API

标签 go ibm-cloud-infrastructure

作为 Golang 的新手(事实上,几天前才开始学习)我有一个非常基本的问题,即创建用于使用 SL API 的客户端代码。

所以我的要求是使用 Golang 调用 createsnapshot SL API,这将拍摄我的耐力卷的快照,前提是卷 ID 是它的输入参数。你能帮我写一个示例代码来写这个客户端吗?

我知道如何在 python 中做到这一点,这是我在 python 中的做法,但现在我想在 golang 中做到这一点(改变要求。你知道 ;))

python 代码片段:

    client = SoftLayer.create_client_from_env("softlayer username", "softlayer apikey")
    result = client['SoftLayer_Network_Storage'].createSnapshot("snapshot_name", "volume id")

谢谢!

最佳答案

如果我没有误解的话,您正在使用 Python 的 Softlayer 包来执行您在给定代码中所做的事情。

Softlayer 也有官方的go包here

通过以下方式下载go环境中的包

go get github.com/softlayer/softlayer-go/...

然后在您的应用程序中导入他的包并使用它。

基本示例:

// 1. Create a session
sess := session.New(username, apikey)

// 2. Get a service
accountService := services.GetAccountService(sess)

// 3. Invoke a method:
account, err := accountService.GetObject()

您需要找到适合您的方法。

关于go - 如何在 Golang 中编写客户端代码来调用 createSnapshot softlayer API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42793054/

相关文章:

rest - 如何将对象过滤器与 softlayer rest api 一起使用?

server - Redis 简单生产服务器规范

go - 如何在 Go 中反序列化 Aerospike 记录?

go - 为什么我在左侧通过多个变量收到 “multiple-value in single-value context”错误

function - Golang - 将结构作为参数传递给函数

python - Softlayer API : change root password and ssh-key operation

go - 将接口(interface)断言为其类型

google-app-engine - SSL : CERTIFICATE_VERIFY_FAILED on GAE/Go

java - 如何使用JAVA在对象存储中创建对象?

swift - openstack4j 可以与 Softlayer(不是 IBM Cloud)Swift 对象存储服务一起使用吗?