Documentation
¶
Overview ¶
Package aliyun contains a library for development around Alibaba Cloud Services.
It aims to provide primitives for making requests to any services, and wrappers/tools around APIs for better user-friendly experience.
The API, Signer & CanonicalizedError are three key primitives that can be used for almost all services.
See sub-packages for API examples.
Index ¶
- Constants
- func FillOSS(v url.Values, o OSS)
- func FormatT(t time.Time) string
- func Get(cl *http.Client, s Signer, a API, host string, resp interface{}) error
- func HandleResp(raw *http.Response, f func([]byte, interface{}) error, resp interface{}) (err error)
- func RandString(n int) string
- func TimeoutClient(d time.Duration) *http.Client
- type API
- type AccessKey
- type Base
- type CanonicalizedError
- type OSS
- type Signer
Constants ¶
const ( XMLFormat = "XML" // default by Aliyun official JSONFormat = "JSON" // force by this package TimeFormat = "2006-01-02T15:04:05Z" // official UTC time format )
Aliyun constants
const ( ErrCodeForbidden = "Forbidden" ErrCodeInternalError = "InternalError" ErrCodeInvalidParameter = "InvalidParameter" ErrCodeUnknownError = "UnknownError" ErrCodeSignatureNonceUsed = "SignatureNonceUsed" ErrCodeUnsupportedHTTPMethod = "UnsupportedHTTPMethod" ErrCodeAPINotFound = "InvalidApi.NotFound" ErrCodeMissingSecurityToken = "MissingSecurityToken" ErrCodeSignatureDoesNotMatch = "SignatureDoesNotMatch" )
some common error codes for all products more on https://error-center.aliyun.com/status/product/Public
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get makes a HTTP GET request to the host for the provided API, and marshal the response into the value pointed by resp.
func HandleResp ¶
func HandleResp(raw *http.Response, f func([]byte, interface{}) error, resp interface{}) (err error)
HandleResp reads the raw HTTP response and checks if any error returned. Errors other than io/json error should be a CanonicalizedError. The body is unmarshaled to the provided interface resp using the function f. If f is nil, it defaults to json.Unmarshal. It is the caller's responsibility to close the body.
func RandString ¶ added in v0.0.2
RandString returns a random string with the given length n.
Types ¶
type API ¶
type API interface { // Param returns the API specific parameters. // These will combine with the common param to get a signature. Param() url.Values // Version returns the API specific version, // usually in the form of a date string. Version() string // Nonce returns a random string to migate repeat-attack. // It gives the freedom for each API to specify it's // own randomness. Nonce() string // Method returns the HTTP method the API used to // make the request. Method() string }
An API abstracts the unique parts of an Aliyun API for a single request. The Signer then signs the API to protect against different attacks.
type AccessKey ¶ added in v0.0.2
type AccessKey struct {
// contains filtered or unexported fields
}
AccessKey is an id-secret pair obtained from Aliyun to access the resources (sign the requests).
func NewAccessKey ¶ added in v0.0.2
NewAccessKey returns a AccessKey to sign the APIs using the JSON format.
type Base ¶ added in v0.0.2
type Base struct{}
Base implements parts for the API with a 32 bytes string nonce and HTTP GET method.
type CanonicalizedError ¶
type CanonicalizedError struct { XMLName xml.Name `json:"-" xml:"Error"` Code string `json:"Code,omitempty" xml:"Code,omitempty"` Message string `json:"Message,omitempty" xml:"Message,omitempty"` RequestID string `json:"RequestId,omitempty" xml:"RequestId,omitempty"` HostID string `json:"HostId,omitempty" xml:"HostId,omitempty"` Status int `json:"status,omitempty"` // from HTTP }
A CanonicalizedError defines the common request response if any error occurs. It also implements the error interface.
func (*CanonicalizedError) Error ¶
func (ce *CanonicalizedError) Error() string
type OSS ¶
type OSS struct { Bucket string `json:"OssBucket"` Endpoint string `json:"OssEndpoint"` Object string `json:"OssObject"` }
An OSS defines a unique OSS resource. OSS is the fundamental service used by most other services.
type Signer ¶
type Signer interface { // Sign signs the API according to the Aliyun specification: // https://help.aliyun.com/document_detail/50284.html & // https://help.aliyun.com/document_detail/50286.html. // It returns the query part of the request including // the signature. Sign(API) string }
A Signer signs the APIs.