openapi

package module
v0.0.0-...-0b043e4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2015 License: Apache-2.0 Imports: 23 Imported by: 44

README

Aliyun OpenAPI Go SDK

GoDoc Build Status

Feature
  • All Aliyun OpenAPI
  • Parameter Validation
  • XML and JSON
  • Struct Result
  • Tested
  • Simple and Easy to use
  • ...
Install

$ go get github.com/cxr29/aliyun-openapi-go-sdk

Usage
package main

import (
	"fmt"
	"os"

	"github.com/cxr29/aliyun-openapi-go-sdk"
	"github.com/cxr29/aliyun-openapi-go-sdk/apis/cdn/v20141111"
)

func fatal(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func main() {
	api := cdn.New("YourAccessKeyId", "YourAccessKeySecret")

	_, err := api.OpenCdnService("PayByBandwidth", nil)
	if err != nil {
		e, ok := err.(openapi.Error)
		if !(ok && e.Code == "CdnService.HasOpened") {
			fatal(err)
		}
	}

	{ // ModifyCdnService
		_, err := api.ModifyCdnService("PayByTraffic", nil)
		fatal(err)
	}

	{ // DescribeCdnService
		result, err := api.DescribeCdnService(nil)
		fatal(err)
		fmt.Printf("DescribeCdnService: %+v\n", result)
	}

	{ // DescribeUserDomains
		optional := openapi.M{
			"PageSize":   int64(10),
			"PageNumber": int64(2),
			"_scheme":    "http",
		}
		result, err := api.DescribeUserDomains(optional)
		fatal(err)
		fmt.Printf("DescribeUserDomains: %+v\n", result)
	}

	// ...
}
API Doc

https://godoc.org/github.com/cxr29/aliyun-openapi-go-sdk

Test
$ export OpenAPITestAccessKeyId=YourAccessKeyId
$ export OpenAPITestAccessKeySecret=YourAccessKeySecret
$ go test -test.v ./tests
Author

Chen Xianren <cxr29@foxmail.com>

Documentation

Overview

Package openapi implements a library of Aliyun OpenAPI.

Index

Constants

View Source
const (
	RegionAPSoutheast1        = "ap-southeast-1"
	RegionCNBeijing           = "cn-beijing"
	RegionCNHangzhou          = "cn-hangzhou"
	RegionCNHangzhouD         = "cn-hangzhou-d"
	RegionCNHongkong          = "cn-hongkong"
	RegionCNQingdao           = "cn-qingdao"
	RegionCNShanghai          = "cn-shanghai"
	RegionCNShanghaiEt2B01    = "cn-shanghai-et2-b01"
	RegionCNShanghaiEt2Test01 = "cn-shanghai-et2-test01"
	RegionCNShenzhen          = "cn-shenzhen"
	RegionUSWest1             = "us-west-1"
)

Region List

Variables

View Source
var Domains = map[string]map[string]string{
	RegionCNHangzhou: {
		"Aas":         "aas.aliyuncs.com",
		"Ace":         "ace.cn-hangzhou.aliyuncs.com",
		"Alert":       "alert.aliyuncs.com",
		"Bss":         "bss.aliyuncs.com",
		"Cdn":         "cdn.aliyuncs.com",
		"Cms":         "metrics.aliyuncs.com",
		"Crm":         "crm-cn-hangzhou.aliyuncs.com",
		"Dqs":         "dqs.aliyuncs.com",
		"Drc":         "drc.aliyuncs.com",
		"Drds":        "drds.aliyuncs.com",
		"Dts":         "dts.aliyuncs.com",
		"Ecs":         "ecs-cn-hangzhou.aliyuncs.com",
		"Emr":         "emr.aliyuncs.com",
		"Location":    "location.aliyuncs.com",
		"M-kvstore":   "m-kvstore.aliyuncs.com",
		"Ocs":         "pop-ocs.aliyuncs.com",
		"Oms":         "oms.aliyuncs.com",
		"Ons":         "ons.aliyuncs.com",
		"Oss":         "oss-cn-hangzhou.aliyuncs.com",
		"OssAdmin":    "oss-admin.aliyuncs.com",
		"Ots":         "ots-pop.aliyuncs.com",
		"PTS":         "pts.aliyuncs.com",
		"Push":        "cloudpush.aliyuncs.com",
		"R-kvstore":   "r-kvstore-cn-hangzhou.aliyuncs.com",
		"ROS":         "ros.aliyuncs.com",
		"Ram":         "ram.aliyuncs.com",
		"Rds":         "rds.aliyuncs.com",
		"Risk":        "risk-cn-hangzhou.aliyuncs.com",
		"Slb":         "slb-pop.aliyuncs.com",
		"Sts":         "sts.aliyuncs.com",
		"Ubsms":       "ubsms.aliyuncs.com",
		"Ubsms-inner": "ubsms-inner.aliyuncs.com",
		"Yundun":      "yundun-cn-hangzhou.aliyuncs.com",
	},
	RegionCNQingdao: {
		"Aas":          "aas.aliyuncs.com",
		"Ace":          "ace.cn-hangzhou.aliyuncs.com",
		"Alert":        "alert.aliyuncs.com",
		"BatchCompute": "batchcompute.cn-qingdao.aliyuncs.com",
		"Bss":          "bss.aliyuncs.com",
		"Cdn":          "cdn.aliyuncs.com",
		"Cms":          "metrics.aliyuncs.com",
		"Crm":          "crm-cn-hangzhou.aliyuncs.com",
		"Dqs":          "dqs.aliyuncs.com",
		"Drc":          "drc.aliyuncs.com",
		"Drds":         "drds.aliyuncs.com",
		"Dts":          "dts.aliyuncs.com",
		"Ecs":          "ecs-cn-hangzhou.aliyuncs.com",
		"Emr":          "emr.aliyuncs.com",
		"Location":     "location.aliyuncs.com",
		"M-kvstore":    "m-kvstore.aliyuncs.com",
		"Ocs":          "pop-ocs.aliyuncs.com",
		"Oms":          "oms.aliyuncs.com",
		"Ons":          "ons.aliyuncs.com",
		"Oss":          "oss-cn-hangzhou.aliyuncs.com",
		"OssAdmin":     "oss-admin.aliyuncs.com",
		"Ots":          "ots-pop.aliyuncs.com",
		"PTS":          "pts.aliyuncs.com",
		"Push":         "cloudpush.aliyuncs.com",
		"R-kvstore":    "r-kvstore-cn-hangzhou.aliyuncs.com",
		"ROS":          "ros.aliyuncs.com",
		"Ram":          "ram.aliyuncs.com",
		"Rds":          "rds.aliyuncs.com",
		"Risk":         "risk-cn-hangzhou.aliyuncs.com",
		"Slb":          "slb-pop.aliyuncs.com",
		"Sts":          "sts.aliyuncs.com",
		"Ubsms":        "ubsms.aliyuncs.com",
		"Ubsms-inner":  "ubsms-inner.aliyuncs.com",
		"Yundun":       "yundun-cn-hangzhou.aliyuncs.com",
	},
	RegionCNShenzhen: {
		"Aas":          "aas.aliyuncs.com",
		"Ace":          "ace.cn-hangzhou.aliyuncs.com",
		"Alert":        "alert.aliyuncs.com",
		"BatchCompute": "batchcompute.cn-shenzhen.aliyuncs.com",
		"Bss":          "bss.aliyuncs.com",
		"Cdn":          "cdn.aliyuncs.com",
		"Cms":          "metrics.aliyuncs.com",
		"Crm":          "crm-cn-hangzhou.aliyuncs.com",
		"Dqs":          "dqs.aliyuncs.com",
		"Drc":          "drc.aliyuncs.com",
		"Drds":         "drds.aliyuncs.com",
		"Dts":          "dts.aliyuncs.com",
		"Ecs":          "ecs-cn-hangzhou.aliyuncs.com",
		"Emr":          "emr.aliyuncs.com",
		"Location":     "location.aliyuncs.com",
		"M-kvstore":    "m-kvstore.aliyuncs.com",
		"Ocs":          "pop-ocs.aliyuncs.com",
		"Oms":          "oms.aliyuncs.com",
		"Ons":          "ons.aliyuncs.com",
		"Oss":          "oss-cn-hangzhou.aliyuncs.com",
		"OssAdmin":     "oss-admin.aliyuncs.com",
		"Ots":          "ots-pop.aliyuncs.com",
		"PTS":          "pts.aliyuncs.com",
		"Push":         "cloudpush.aliyuncs.com",
		"R-kvstore":    "r-kvstore-cn-hangzhou.aliyuncs.com",
		"ROS":          "ros.aliyuncs.com",
		"Ram":          "ram.aliyuncs.com",
		"Rds":          "rds.aliyuncs.com",
		"Risk":         "risk-cn-hangzhou.aliyuncs.com",
		"Slb":          "slb-pop.aliyuncs.com",
		"Sts":          "sts.aliyuncs.com",
		"Ubsms":        "ubsms.aliyuncs.com",
		"Ubsms-inner":  "ubsms-inner.aliyuncs.com",
		"Yundun":       "yundun-cn-hangzhou.aliyuncs.com",
	},
}

Domains [Endpoint][Product]:Domain

Regions [Region]:Endpoint

View Source
var UserAgent = "aliyun-openapi-go-sdk"

UserAgent is the default user agent and is used by GetRequest.

Functions

func CanonicalizedHeader

func CanonicalizedHeader(header http.Header, prefix string) string

CanonicalizedHeader canonicalized the prefix headers.

func CanonicalizedQuery

func CanonicalizedQuery(q url.Values, escape bool) string

CanonicalizedQuery canonicalized the query, if the escape is true the key and value are escaped.

func GetDomain

func GetDomain(product, region string) string

GetDomain returns the access domain given a product and optional region.

func HmacSha1

func HmacSha1(secret, data string) string

HmacSha1 returns the base64 HMAC-SHA1 hash of the data using the given secret.

func HmacSha256

func HmacSha256(secret, data string) string

HmacSha256 returns the base64 HMAC-SHA256 hash of the data using the given secret.

func HmacX

func HmacX(secret, data string, h func() hash.Hash) string

HmacX returns the base64 HMAC-X hash of the data using the given secret.

The SHA1 is used if the given hash.Hash type is nil.

func IsIn

func IsIn(s, v string) bool

IsIn returns true if s in the vertical bar separated v.

func Md5sum

func Md5sum(data []byte) string

Md5sum returns the base64 MD5 checksum of the data.

func ReadBody

func ReadBody(res *http.Response, v interface{}) error

ReadBody reads the response body and stores the result in the value pointed to by v,

When the status code is 4xx or 5xx return the Error.

If v is nil, the response body is discarded or, if v's type is not *[]byte, *os.File and *bytes.Buffer, then decode XML or JSON to it.

Content-Encoding deflate and gzip are supported.

func SignatureROA

func SignatureROA(accessKeyId, accessKeySecret string, method string, path string, query url.Values, header http.Header)

SignatureROA signature the ROA api style and set the Authorization header.

func SignatureRPC

func SignatureRPC(accessKeyId, accessKeySecret, method string, query url.Values)

SignatureRPC signature the RPC api style and set the Signature query.

Types

type Error

type Error struct {
	Code      string
	Message   string
	RequestId string
	HostId    string
}

Error represents the error response when the status code is 4xx or 5xx.

Relevant documentation:

https://docs.aliyun.com/#/pub/ecs/open-api/requestmethod&commonresponse

func (Error) Error

func (e Error) Error() string

type M

type M map[string]interface{}

M represents optional parameters.

type Params

type Params struct {
	Product     string
	Style       string
	Version     string
	Method      string
	Scheme      string
	Region      string
	Pattern     string
	Path        map[string]string
	Query, Body url.Values
	Header      http.Header
}

A Params represents the request parameters.

func NewParams

func NewParams() Params

NewParams returns a initialized Params.

func (Params) Expand

func (args Params) Expand() string

Expand returns the string of pattern with all the text between square brackets are replaced by the corresponding path value.

type Response

type Response struct {
	XMLName   xml.Name `json:"-"`
	RequestId string
}

Response represents a response only returns RequestId.

type Service

type Service struct {
	Method          string
	Unsafe          bool
	Domain          string
	AccessKeyId     string
	AccessKeySecret string
}

Service represents Aliyun Open API Service, the AccessKeyId and the AccessKeySecret are required.

func NewService

func NewService(accessKeyId, accessKeySecret string) Service

NewService returns a new Service given a accessKeyId and accessKeySecret.

func (Service) Do

func (s Service) Do(v interface{}, args Params) error

Do sends an HTTP request and read the HTTP response to v.

See the method GetResponse and the function ReadBody to get more.

func (Service) GetRequest

func (s Service) GetRequest(args Params) (*http.Request, error)

GetRequest returns a new Request given a Params.

func (Service) GetResponse

func (s Service) GetResponse(args Params) (*http.Response, error)

GetResponse sends an HTTP request and returns the HTTP response.

See the method GetRequest to get more.

func (Service) Scheme

func (s Service) Scheme() string

Scheme returns http if the Unsafe is ture otherwise returns https.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL