安装 SDK
GolangSDK 使用说明:https://help.aliyun.com/document_detail/63640.html
调用 Codeup API
以 CreateRepository 为例:
创建个人访问令牌见 个人访问令牌
package main
import (
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)
func main() {
client, err := sdk.NewClientWithAccessKey("cn-hangzhou", "<accessKeyId>", "<accessSecret>")
if err != nil {
panic(err)
}
request := requests.NewCommonRequest()
request.Method = "POST"
request.Scheme = "https" // https | http
request.Domain = "codeup.cn-hangzhou.aliyuncs.com"
request.Version = "2020-04-14"
request.PathPattern = "/api/v3/projects"
request.Headers["Content-Type"] = "application/json"
request.QueryParams["RegionId"] = "cn-hangzhou"
request.QueryParams["OrganizationId"] = "<OrganizationId>"
body := `{
"name": "<RepoName>",
"path": "<RepoPath>",
"visibility_level": 10,
"namespace_id": 123
}`
request.Content = []byte(body)
response, err := client.ProcessCommonRequest(request)
if err != nil {
panic(err)
}
fmt.Print(response.GetHttpContentString())
}
文档内容是否对您有帮助?