client

package
v1.5.31 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

client 包 核心代码包,请求相关代码, 如:client request response 其中也包括整个sdk的一下基本信息 @author cbping

Index

Constants

View Source
const (
	DefaultSignatureVersion = "1.0"
	DefaultSignatureMethod  = "HMAC-SHA1"
	JSONResponseFormat      = "JSON"
	XMLResponseFormat       = "XML"
	ECSRequestMethod        = "GET"
)

常量

View Source
const (
	ApiCDNVersion = "2014-11-11"
	ApiCDNHost    = "https://cdn.aliyuncs.com/"
)
View Source
const Version = "0.1.2"

版本号

Variables

This section is empty.

Functions

This section is empty.

Types

type CDNRequest

type CDNRequest struct {
	Format           string
	Version          string
	AccessKeyId      string
	Signature        string
	SignatureMethod  string
	Timestamp        util.ISO6801Time
	SignatureVersion string
	SignatureNonce   string
	// ResourceOwnerAccount string
	Action string

	// http
	Host   string
	Method string
	Url    string
	Args   url.Values
}
cdn 请求对象。实现 Request 接口

名称 类型 是否必须 描述 Format String 否 返回值的类型,支持JSON与XML。默认为XML \n Version String 是 API版本号,为日期形式:YYYY-MM-DD,本版本对应为2014-11-11 \n AccessKeyId String 是 阿里云颁发给用户的访问服务所用的密钥ID \n Signature String 是 签名结果串,关于签名的计算方法,请参见签名机制。\n SignatureMethod String 是 签名方式,目前支持HMAC-SHA1 \n Timestamp String 是 请求的时间戳。日期格式按照ISO8601标准表示,并需要使用UTC时间。格式为:YYYY-MM-DDThh:mm:ssZ。例如,2014-11-11T12:00:00Z(为北京时间2014年11月11日20点0分0秒)\n SignatureVersion String 是 签名算法版本,目前版本是1.0 \n SignatureNonce String 是 唯一随机数,用于防止网络重放攻击。用户在不同请求间要使用不同的随机数值 \n

func NewCDNRequest

func NewCDNRequest(action string) *CDNRequest

生成CDNRequest

func (*CDNRequest) Clone

func (l *CDNRequest) Clone() interface{}

克隆

func (*CDNRequest) DeadLine

func (Cdn *CDNRequest) DeadLine() time.Duration

A Timeout of zero means no timeout.

func (*CDNRequest) DelArgs

func (Cdn *CDNRequest) DelArgs(key string)

func (*CDNRequest) HttpRequestInstance

func (Cdn *CDNRequest) HttpRequestInstance() (httpReq *http.Request, err error)

func (*CDNRequest) ResponseFormat

func (Cdn *CDNRequest) ResponseFormat() string

func (*CDNRequest) SetArgs

func (Cdn *CDNRequest) SetArgs(key, value string)

func (*CDNRequest) Sign

func (Cdn *CDNRequest) Sign(cert *Credentials)

签名

func (*CDNRequest) String

func (Cdn *CDNRequest) String() string

func (*CDNRequest) StructToArgs

func (Cdn *CDNRequest) StructToArgs()

CDNRequest的必要字段转成参数

type Client

type Client struct {
	*Credentials

	ConnectTimeout time.Duration
	// contains filtered or unexported fields
}

客户端 处理http请求

func NewClient

func NewClient(cert *Credentials) (c *Client)

func NewClientTimeout

func NewClientTimeout(cert *Credentials, connectTimeout time.Duration) (c *Client)

func (*Client) Init

func (c *Client) Init() *Client

初始化

func (*Client) Query

func (c *Client) Query(req Request, resp interface{}) error

处理请求

func (*Client) SetDebug

func (c *Client) SetDebug(debug bool)

type Credentials

type Credentials struct {
	//Access Key Id
	AccessKeyId string
	//Access Key Secret
	AccessKeySecret string
}

Api请求凭证

func NewCredentials

func NewCredentials(accessKeyId, accessKeySecret string) *Credentials

type ErrorResponse

type ErrorResponse struct {
	RequestId  string
	HostId     string
	Code       string
	Message    string
	StatusCode int //Status Code of HTTP Response
}

错误信息结构体

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type Request

type Request interface {
	//签名
	Sign(*Credentials)
	//返回*http.Request
	HttpRequestInstance() (*http.Request, error)
	//返回值的类型,支持JSON与XML.
	ResponseFormat() string
	//
	String() string
	//
	Clone() interface{}
}

请求接口

所有请求对象继承的接口,也是Client接受处理的请求接口
签名方式和必要参数信息。

type Response

type Response struct {
	RequestId string
}

type Unmarshal

type Unmarshal func(data []byte, v interface{}) error

Jump to

Keyboard shortcuts

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