130 lines
2.6 KiB
Go
130 lines
2.6 KiB
Go
|
package requests
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
RPC = "RPC"
|
||
|
ROA = "ROA"
|
||
|
|
||
|
HTTP = "HTTP"
|
||
|
HTTPS = "HTTPS"
|
||
|
|
||
|
DefaultHttpPort = "80"
|
||
|
|
||
|
GET = "GET"
|
||
|
PUT = "PUT"
|
||
|
POST = "POST"
|
||
|
DELETE = "DELETE"
|
||
|
PATCH = "PATCH"
|
||
|
HEAD = "HEAD"
|
||
|
OPTIONS = "OPTIONS"
|
||
|
|
||
|
Json = "application/json"
|
||
|
Xml = "application/xml"
|
||
|
Raw = "application/octet-stream"
|
||
|
Form = "application/x-www-form-urlencoded"
|
||
|
|
||
|
Header = "Header"
|
||
|
Query = "Query"
|
||
|
Body = "Body"
|
||
|
Path = "Path"
|
||
|
|
||
|
HeaderSeparator = "\n"
|
||
|
)
|
||
|
|
||
|
type AcsRequest interface {
|
||
|
GetReadTimeout() time.Duration
|
||
|
GetConnectTimeout() time.Duration
|
||
|
SetReadTimeout(readTimeOut time.Duration)
|
||
|
SetConnectTimeout(connectTimeOut time.Duration)
|
||
|
SetHTTPSInsecure(isInsecure bool)
|
||
|
GetHTTPSInsecure() *bool
|
||
|
GetQueryParams() map[string]string
|
||
|
GetFormParams() map[string]string
|
||
|
GetMethod() string
|
||
|
SetStringToSign(stringToSign string)
|
||
|
}
|
||
|
|
||
|
type baseRequest struct {
|
||
|
Scheme string
|
||
|
Method string
|
||
|
Host string
|
||
|
Domain string
|
||
|
From string
|
||
|
ReadTimeout time.Duration
|
||
|
ConnectTimeout time.Duration
|
||
|
isInsecure *bool
|
||
|
|
||
|
AcceptFormat string
|
||
|
|
||
|
userAgent map[string]string
|
||
|
product string
|
||
|
version string
|
||
|
|
||
|
QueryParams map[string]string
|
||
|
Headers map[string]string
|
||
|
FormParams map[string]string
|
||
|
Content []byte
|
||
|
|
||
|
queries string
|
||
|
stringToSign string
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) GetMethod() string {
|
||
|
return request.Method
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) GetFormParams() map[string]string {
|
||
|
return request.FormParams
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) GetQueryParams() map[string]string {
|
||
|
return request.QueryParams
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) SetHTTPSInsecure(isInsecure bool) {
|
||
|
request.isInsecure = &isInsecure
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) GetHTTPSInsecure() *bool {
|
||
|
return request.isInsecure
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) GetReadTimeout() time.Duration {
|
||
|
return request.ReadTimeout
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) GetConnectTimeout() time.Duration {
|
||
|
return request.ConnectTimeout
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) SetReadTimeout(readTimeOut time.Duration) {
|
||
|
request.ReadTimeout = readTimeOut
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) SetConnectTimeout(connectTimeOut time.Duration) {
|
||
|
request.ConnectTimeout = connectTimeOut
|
||
|
}
|
||
|
|
||
|
func (request *baseRequest) SetStringToSign(stringToSign string) {
|
||
|
request.stringToSign = stringToSign
|
||
|
}
|
||
|
|
||
|
func defaultBaseRequest() (request *baseRequest) {
|
||
|
request = &baseRequest{
|
||
|
Scheme: "",
|
||
|
AcceptFormat: "JSON",
|
||
|
Method: GET,
|
||
|
QueryParams: make(map[string]string),
|
||
|
Headers: map[string]string{
|
||
|
"x-sdk-client": "golang/1.0.0",
|
||
|
"x-sdk-invoke-type": "normal",
|
||
|
"Accept-Encoding": "identity",
|
||
|
},
|
||
|
FormParams: make(map[string]string),
|
||
|
}
|
||
|
return
|
||
|
}
|