common

package
v0.0.0-...-ab98a91 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 20 Imported by: 824

Documentation

Index

Constants

View Source
const (
	HTTP_PROTOCOL  = "http"
	HTTPS_PROTOCOL = "https"
)
View Source
const (
	Hangzhou    = Region("cn-hangzhou")
	Qingdao     = Region("cn-qingdao")
	Beijing     = Region("cn-beijing")
	Hongkong    = Region("cn-hongkong")
	Shenzhen    = Region("cn-shenzhen")
	Shanghai    = Region("cn-shanghai")
	Zhangjiakou = Region("cn-zhangjiakou")
	Huhehaote   = Region("cn-huhehaote")

	Chengdu = Region("cn-chengdu")

	APSouthEast1 = Region("ap-southeast-1")
	APNorthEast1 = Region("ap-northeast-1")
	APSouthEast2 = Region("ap-southeast-2")
	APSouthEast3 = Region("ap-southeast-3")
	APSouthEast5 = Region("ap-southeast-5")

	APSouth1 = Region("ap-south-1")

	USWest1 = Region("us-west-1")
	USEast1 = Region("us-east-1")

	MEEast1 = Region("me-east-1")

	EUCentral1 = Region("eu-central-1")
	EUWest1    = Region("eu-west-1")

	ShenZhenFinance = Region("cn-shenzhen-finance-1")
	ShanghaiFinance = Region("cn-shanghai-finance-1")
	HangZhouFinance = Region("cn-hangzhou-finance-1")

	CNNorth2Gov1 = Region("cn-north-2-gov-1")
	RUSWest1     = Region("rus-west-1")
)

Constants of region definition

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

Constants for Aliyun API requests

View Source
const (
	PayByBandwidth = InternetChargeType("PayByBandwidth")
	PayByTraffic   = InternetChargeType("PayByTraffic")
)
View Source
const (
	PrePaid  = InstanceChargeType("PrePaid")
	PostPaid = InstanceChargeType("PostPaid")
)
View Source
const (
	Internet = NetType("Internet")
	Intranet = NetType("Intranet")
)
View Source
const (
	Hour  = TimeType("Hour")
	Day   = TimeType("Day")
	Week  = TimeType("Week")
	Month = TimeType("Month")
	Year  = TimeType("Year")
)
View Source
const (
	Classic = NetworkType("Classic")
	VPC     = NetworkType("VPC")
)
View Source
const Version = "0.1"

Variables

View Source
var CentralDomainServices = map[string]string{
	"pvtz": "pvtz.vpc-proxy.aliyuncs.com",
}
View Source
var RegionalDomainServices = []string{
	"ecs",
	"vpc",
	"slb",
}
View Source
var (
	SpecailEnpoints = map[Region]map[string]string{
		APNorthEast1: {
			"ecs": "https://ecs.ap-northeast-1.aliyuncs.com",
			"slb": "https://slb.ap-northeast-1.aliyuncs.com",
			"rds": "https://rds.ap-northeast-1.aliyuncs.com",
			"vpc": "https://vpc.ap-northeast-1.aliyuncs.com",
		},
		APSouthEast2: {
			"ecs": "https://ecs.ap-southeast-2.aliyuncs.com",
			"slb": "https://slb.ap-southeast-2.aliyuncs.com",
			"rds": "https://rds.ap-southeast-2.aliyuncs.com",
			"vpc": "https://vpc.ap-southeast-2.aliyuncs.com",
		},
		APSouthEast3: {
			"ecs": "https://ecs.ap-southeast-3.aliyuncs.com",
			"slb": "https://slb.ap-southeast-3.aliyuncs.com",
			"rds": "https://rds.ap-southeast-3.aliyuncs.com",
			"vpc": "https://vpc.ap-southeast-3.aliyuncs.com",
		},
		MEEast1: {
			"ecs": "https://ecs.me-east-1.aliyuncs.com",
			"slb": "https://slb.me-east-1.aliyuncs.com",
			"rds": "https://rds.me-east-1.aliyuncs.com",
			"vpc": "https://vpc.me-east-1.aliyuncs.com",
		},
		EUCentral1: {
			"ecs": "https://ecs.eu-central-1.aliyuncs.com",
			"slb": "https://slb.eu-central-1.aliyuncs.com",
			"rds": "https://rds.eu-central-1.aliyuncs.com",
			"vpc": "https://vpc.eu-central-1.aliyuncs.com",
		},
		EUWest1: {
			"ecs": "https://ecs.eu-west-1.aliyuncs.com",
			"slb": "https://slb.eu-west-1.aliyuncs.com",
			"rds": "https://rds.eu-west-1.aliyuncs.com",
			"vpc": "https://vpc.eu-west-1.aliyuncs.com",
		},
		Zhangjiakou: {
			"ecs": "https://ecs.cn-zhangjiakou.aliyuncs.com",
			"slb": "https://slb.cn-zhangjiakou.aliyuncs.com",
			"rds": "https://rds.cn-zhangjiakou.aliyuncs.com",
			"vpc": "https://vpc.cn-zhangjiakou.aliyuncs.com",
		},
		Huhehaote: {
			"ecs": "https://ecs.cn-huhehaote.aliyuncs.com",
			"slb": "https://slb.cn-huhehaote.aliyuncs.com",
			"rds": "https://rds.cn-huhehaote.aliyuncs.com",
			"vpc": "https://vpc.cn-huhehaote.aliyuncs.com",
		},
	}
)
View Source
var SpecialDeployedProducts = map[string]map[Region]interface{}{
	"vpc": {
		Hangzhou:     Hangzhou,
		Shenzhen:     Shenzhen,
		APSouthEast1: APSouthEast1,
		USWest1:      USWest1,
		USEast1:      USEast1,
		Chengdu:      Chengdu,
		Zhangjiakou:  Zhangjiakou,
		Huhehaote:    Huhehaote,
		APSouthEast3: APSouthEast3,
		EUCentral1:   EUCentral1,
		EUWest1:      EUWest1,
		APSouth1:     APSouth1,
		APNorthEast1: APNorthEast1,
		APSouthEast5: APSouthEast5,
		APSouthEast2: APSouthEast2,
		MEEast1:      MEEast1,
		CNNorth2Gov1: CNNorth2Gov1,
	},
}
View Source
var UnitRegions = map[Region]interface{}{
	Hangzhou:     Hangzhou,
	Shenzhen:     Shenzhen,
	APSouthEast1: APSouthEast1,
	USWest1:      USWest1,
	USEast1:      USEast1,
	Chengdu:      Chengdu,
	Zhangjiakou:  Zhangjiakou,
	Huhehaote:    Huhehaote,
	APSouthEast3: APSouthEast3,
	EUCentral1:   EUCentral1,
	EUWest1:      EUWest1,
	APSouth1:     APSouth1,
	APNorthEast1: APNorthEast1,
	APSouthEast5: APSouthEast5,
	APSouthEast2: APSouthEast2,
	CNNorth2Gov1: CNNorth2Gov1,

	HangZhouFinance: Hangzhou,
}

Unit-Domain of central product

Functions

func GetClientError

func GetClientError(err error) error

func GetClientErrorFromString

func GetClientErrorFromString(str string) error

func GetCustomError

func GetCustomError(code, message string) error

func IsValidRegion

func IsValidRegion(r string) bool

IsValidRegion checks if r is an Ali supported region.

func TransToString

func TransToString(object interface{}) string

Types

type APIEndpoints

type APIEndpoints struct {
	Endpoint []EndpointItem
}

type BusinessInfo

type BusinessInfo struct {
	Pack       string `json:"pack,omitempty"`
	ActivityId string `json:"activityId,omitempty"`
}

type Client

type Client struct {
	AccessKeyId     string //Access Key Id
	AccessKeySecret string //Access Key Secret
	// contains filtered or unexported fields
}

A Client represents a client of ECS services

func (*Client) CloseLogger

func (client *Client) CloseLogger()

func (*Client) GenerateClientToken

func (client *Client) GenerateClientToken() string

GenerateClientToken generates the Client Token with random string

func (*Client) GetEndpoint

func (client *Client) GetEndpoint() string

func (*Client) GetLogger

func (client *Client) GetLogger() *Logger

func (*Client) GetLoggerMsg

func (client *Client) GetLoggerMsg() string

func (*Client) GetTemplate

func (client *Client) GetTemplate() string

func (*Client) Init

func (client *Client) Init(endpoint, version, accessKeyId, accessKeySecret string)

Initialize properties of a client instance

func (*Client) InitClient

func (client *Client) InitClient() *Client

Intialize client object when all properties are ready

func (*Client) InitClient4RegionalDomain

func (client *Client) InitClient4RegionalDomain() *Client

Intialize client object when all properties are ready only for regional domain hz

func (*Client) Invoke

func (client *Client) Invoke(action string, args interface{}, response interface{}) (err error)

Invoke sends the raw HTTP request for ECS services

func (*Client) InvokeByAnyMethod

func (client *Client) InvokeByAnyMethod(method, action, path string, args interface{}, response interface{}) (err error)

Invoke sends the raw HTTP request for ECS services 改进了一下上面那个方法,可以使用各种Http方法 2017.1.30 增加了一个path参数,用来拓展访问的地址

func (*Client) InvokeByFlattenMethod

func (client *Client) InvokeByFlattenMethod(action string, args interface{}, response interface{}) (err error)

Invoke sends the raw HTTP request for ECS services

func (*Client) NewInit

func (client *Client) NewInit(endpoint, version, accessKeyId, accessKeySecret, serviceCode string, regionID Region)

Initialize properties of a client instance including regionID

func (*Client) NewInit4RegionalDomain

func (client *Client) NewInit4RegionalDomain(endpoint, version, accessKeyId, accessKeySecret, serviceCode string, regionID Region)

Initialize properties of a client instance including regionID only for hz regional Domain

func (*Client) NewInitForAssumeRole

func (client *Client) NewInitForAssumeRole(endpoint, version, accessKeyId, accessKeySecret, serviceCode string, regionID Region, securityToken string)

func (*Client) OpenLogger

func (client *Client) OpenLogger()

func (*Client) SetAccessKeyId

func (client *Client) SetAccessKeyId(id string)

SetAccessKeyId sets new AccessKeyId

func (*Client) SetAccessKeySecret

func (client *Client) SetAccessKeySecret(secret string)

SetAccessKeySecret sets new AccessKeySecret

func (*Client) SetBusinessInfo

func (client *Client) SetBusinessInfo(businessInfo string)

SetBusinessInfo sets business info to log the request/response message

func (*Client) SetDebug

func (client *Client) SetDebug(debug bool)

SetDebug sets debug mode to log the request/response message

func (*Client) SetDisableTrace

func (client *Client) SetDisableTrace(disableTrace bool)

SetDisableTrace close trace mode

func (*Client) SetEndpoint

func (client *Client) SetEndpoint(endpoint string)

SetEndpoint sets custom endpoint

func (*Client) SetLogger

func (client *Client) SetLogger(level string, channel string, out io.Writer, template string)

func (*Client) SetRegionID

func (client *Client) SetRegionID(regionID Region)

SetEndpoint sets Region ID

func (*Client) SetSecurityToken

func (client *Client) SetSecurityToken(securityToken string)

set SecurityToken

func (*Client) SetServiceCode

func (client *Client) SetServiceCode(serviceCode string)

SetServiceCode sets serviceCode

func (*Client) SetSpan

func (client *Client) SetSpan(span opentracing.Span)

SetSpan set the parent span

func (*Client) SetTemplate

func (client *Client) SetTemplate(template string)

func (*Client) SetTransport

func (client *Client) SetTransport(transport http.RoundTripper)

SetTransport sets transport to the http client

func (*Client) SetUserAgent

func (client *Client) SetUserAgent(userAgent string)

SetUserAgent sets user agent to the request/response message

func (*Client) SetVersion

func (client *Client) SetVersion(version string)

SetEndpoint sets custom version

func (*Client) WithAccessKeyId

func (client *Client) WithAccessKeyId(id string) *Client

WithAccessKeyId sets new AccessKeyId

func (*Client) WithAccessKeySecret

func (client *Client) WithAccessKeySecret(secret string) *Client

WithAccessKeySecret sets new AccessKeySecret

func (*Client) WithBusinessInfo

func (client *Client) WithBusinessInfo(businessInfo string) *Client

WithBusinessInfo sets business info to log the request/response message

func (*Client) WithDebug

func (client *Client) WithDebug(debug bool) *Client

WithDebug sets debug mode to log the request/response message

func (*Client) WithDisableTrace

func (client *Client) WithDisableTrace(disableTrace bool) *Client

WithUserAgent sets user agent to the request/response message

func (*Client) WithEndpoint

func (client *Client) WithEndpoint(endpoint string) *Client

WithEndpoint sets custom endpoint

func (*Client) WithRegionID

func (client *Client) WithRegionID(regionID Region) *Client

WithRegionID sets Region ID

func (*Client) WithSecurityToken

func (client *Client) WithSecurityToken(securityToken string) *Client

WithSecurityToken sets securityToken

func (*Client) WithServiceCode

func (client *Client) WithServiceCode(serviceCode string) *Client

WithServiceCode sets serviceCode

func (*Client) WithSpan

func (client *Client) WithSpan(span opentracing.Span) *Client

WithUserAgent sets user agent to the request/response message

func (*Client) WithUserAgent

func (client *Client) WithUserAgent(userAgent string) *Client

WithUserAgent sets user agent to the request/response message

func (*Client) WithVersion

func (client *Client) WithVersion(version string) *Client

WithVersion sets custom version

type DescribeEndpointArgs

type DescribeEndpointArgs struct {
	Id          Region
	ServiceCode string
	Type        string
}

type DescribeEndpointResponse

type DescribeEndpointResponse struct {
	Response
	EndpointItem
}

type DescribeEndpointsArgs

type DescribeEndpointsArgs struct {
	Id          Region
	ServiceCode string
	Type        string
}

type DescribeEndpointsResponse

type DescribeEndpointsResponse struct {
	Response
	Endpoints APIEndpoints
	RequestId string
	Success   bool
}

type Endpoint

type Endpoint struct {
	Name      string    `xml:"name,attr"`
	RegionIds RegionIds `xml:"RegionIds"`
	Products  Products  `xml:"Products"`
}

type EndpointItem

type EndpointItem struct {
	Protocols struct {
		Protocols []string
	}
	Type        string
	Namespace   string
	Id          Region
	SerivceCode string
	Endpoint    string
}

type Endpoints

type Endpoints struct {
	Endpoint []Endpoint `xml:"Endpoint"`
}

xml

type Error

type Error struct {
	ErrorResponse
	StatusCode int //Status Code of HTTP Response
}

An Error represents a custom error for Aliyun API failure response

func (*Error) Error

func (e *Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Response
	HostId  string
	Code    string
	Message string
}

type FlattenArray

type FlattenArray []string

RemovalPolicy.N add index to array item RemovalPolicy=["a", "b"] => RemovalPolicy.1="a" RemovalPolicy.2="b"

type InstanceChargeType

type InstanceChargeType string

type InternetChargeType

type InternetChargeType string

type LocationClient

type LocationClient struct {
	Client
}

func NewLocationClient

func NewLocationClient(accessKeyId, accessKeySecret, securityToken string) *LocationClient

func NewLocationClientWithSecurityToken

func NewLocationClientWithSecurityToken(accessKeyId, accessKeySecret, securityToken string) *LocationClient

func (*LocationClient) DescribeEndpoint

func (client *LocationClient) DescribeEndpoint(args *DescribeEndpointArgs) (*DescribeEndpointResponse, error)

func (*LocationClient) DescribeEndpoints

func (client *LocationClient) DescribeEndpoints(args *DescribeEndpointsArgs) (*DescribeEndpointsResponse, error)

func (*LocationClient) DescribeOpenAPIEndpoint

func (client *LocationClient) DescribeOpenAPIEndpoint(region Region, serviceCode string) string

type Logger

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

type NetType

type NetType string

type NetworkType

type NetworkType string

type Pagination

type Pagination struct {
	PageNumber int
	PageSize   int
}

func (*Pagination) SetPageSize

func (p *Pagination) SetPageSize(size int)

func (*Pagination) Validate

func (p *Pagination) Validate()

type PaginationResult

type PaginationResult struct {
	TotalCount int
	PageNumber int
	PageSize   int
}

A PaginationResponse represents a response with pagination information

func (*PaginationResult) NextPage

func (r *PaginationResult) NextPage() *Pagination

NextPage gets the next page of the result set

type Product

type Product struct {
	ProductName string `xml:"ProductName"`
	DomainName  string `xml:"DomainName"`
}

type Products

type Products struct {
	Product []Product `xml:"Product"`
}

type Region

type Region string

Region represents ECS region

type RegionIds

type RegionIds struct {
	RegionId string `xml:"RegionId"`
}

type Request

type Request struct {
	Format               string
	Version              string
	RegionId             Region
	AccessKeyId          string
	SecurityToken        string
	Signature            string
	SignatureMethod      string
	Timestamp            util.ISO6801Time
	SignatureVersion     string
	SignatureNonce       string
	ResourceOwnerAccount string
	Action               string
}

type Response

type Response struct {
	RequestId string
}

type TimeType

type TimeType string

type UnderlineString

type UnderlineString string

string contains underline which will be replaced with dot SystemDisk_Category => SystemDisk.Category

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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