Golang SDK 示例

安装 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())
}