Step By Step
1、开发环境搭建
2、SDK安装
go get -u github.com/aliyun/alibaba-cloud-sdk-go/sdk
3、Code Sample
import (
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ons"
)
func main() {
// 阿里云常见参数获取位置:https://developer.aliyun.com/article/693979?spm=a2c6h.13262185.0.0.9a635eb5Guoqxk
client, err := ons.NewClientWithAccessKey("cn-shanghai", "LTAIOZZg********", "v7CjUJCMk7j9aK****************")
request := ons.CreateOnsTopicListRequest()
request.Scheme = "https"
request.InstanceId = "MQ_INST_18482178********_BXRhsEvb"
response, err := client.OnsTopicList(request)
if err != nil {
fmt.Print(err.Error())
}
fmt.Printf("response is %#v\n", response)
}
4、测试结果
response is &ons.OnsTopicListResponse{BaseResponse:(*responses.BaseResponse)(0xc00002a840), RequestId:"941AAB66-E221-46A4-8A46-9231********", HelpUrl:"", Data:ons.DataInOnsTopicList{PublishInfoDo:[]ons.PublishInfoDo{ons.PublishInfoDo{Topic:"newhttptopic", Owner:"18482178********", Relation:1, RelationName:"所有者", CreateTime:1598540117000, Remark:"********", MessageType:0, InstanceId:"MQ_INST_18482178********_BXRhsEvb", IndependentNaming:true}, ons.PublishInfoDo{Topic:"http", Owner:"18482178********", Relation:1, RelationName:"所有者", CreateTime:1598539120000, Remark:"********", MessageType:0, InstanceId:"MQ_INST_18482178********_BXRhsEvb", IndependentNaming:true}}}}
5、异常解决
部分接口请求的时候会出现证书认证异常,可以将:request.Scheme = "https" 替换为:request.Scheme = "http"即可。