Documentation ¶
Overview ¶
This core package providers API and clients base struct for services, and also some infrastructure function, such as signer, send http(s) request and so on.
Index ¶
- Constants
- func EscapePath(path string, encodeSep bool) string
- type Config
- type Credential
- type DefaultLogger
- type ErrorResponse
- type JDCloudClient
- type JDCloudRequest
- type Logger
- type ParameterBuilder
- type RequestInterface
- type ResponseProcessor
- type SignFunc
- type Signer
- type WithBodyBuilder
- type WithBodyResponseProcessor
- type WithoutBodyBuilder
- type WithoutBodyResponseProcessor
Constants ¶
const ( SchemeHttp = "http" SchemeHttps = "https" MethodGet = "GET" MethodPut = "PUT" MethodPost = "POST" MethodDelete = "DELETE" MethodPatch = "PATCH" MethodHead = "HEAD" HeaderJcloudPrefix = "x-jcloud" HeaderJdcloudPrefix = "x-jdcloud" HeaderJdcloudRequestId = "x-jdcloud-request-id" )
const ( LogFatal = iota LogError LogWarn LogInfo )
const Version = "1.0.3"
Variables ¶
This section is empty.
Functions ¶
func EscapePath ¶
EscapePath escapes part of a URL path
Types ¶
type Config ¶
func NewConfig ¶
func NewConfig() *Config
NewConfig returns a pointer of Config
scheme only accepts http or https
endpoint is the host to access, the connection could not be created if it's error
func (*Config) SetEndpoint ¶
func (*Config) SetTimeout ¶
type Credential ¶
Credential is used to sign the request, AccessKey and SecretKey could be found in JDCloud console
func NewCredentials ¶
func NewCredentials(accessKey, secretKey string) *Credential
type DefaultLogger ¶
type DefaultLogger struct {
Level int
}
func NewDefaultLogger ¶
func NewDefaultLogger(level int) *DefaultLogger
func (DefaultLogger) Log ¶
func (logger DefaultLogger) Log(level int, message ...interface{})
type ErrorResponse ¶
type JDCloudClient ¶
type JDCloudClient struct { Credential Credential Config Config ServiceName string Revision string Logger Logger }
JDCloudClient is the base struct of service clients
func (JDCloudClient) Send ¶
func (c JDCloudClient) Send(request RequestInterface, serviceName string) ([]byte, error)
Send send the request and return the response to the client. Parameter request accepts concrete request object which follow RequestInterface.
type JDCloudRequest ¶
type JDCloudRequest struct { URL string // resource url, i.e. /regions/${regionId}/elasticIps/${elasticIpId} Method string Header map[string]string Version string }
JDCloudRequest is the base struct of service requests
func (*JDCloudRequest) AddHeader ¶
func (r *JDCloudRequest) AddHeader(key, value string)
AddHeader only adds pin or erp, they will be encoded to base64 code
func (JDCloudRequest) GetHeaders ¶
func (r JDCloudRequest) GetHeaders() map[string]string
func (JDCloudRequest) GetMethod ¶
func (r JDCloudRequest) GetMethod() string
func (JDCloudRequest) GetURL ¶
func (r JDCloudRequest) GetURL() string
func (JDCloudRequest) GetVersion ¶
func (r JDCloudRequest) GetVersion() string
type ParameterBuilder ¶
type ParameterBuilder interface { BuildURL(url string, paramJson []byte) (string, error) BuildBody(paramJson []byte) (string, error) }
func GetParameterBuilder ¶
func GetParameterBuilder(method string, logger Logger) ParameterBuilder
type RequestInterface ¶
type ResponseProcessor ¶
func GetResponseProcessor ¶
func GetResponseProcessor(method string) ResponseProcessor
type Signer ¶
type Signer struct { Credentials Credential Logger Logger }
func NewSigner ¶
func NewSigner(credsProvider Credential, logger Logger) *Signer
type WithBodyBuilder ¶
type WithBodyBuilder struct {
Logger Logger
}
WithBodyBuilder supports PUT/POST/PATCH methods. It has path and body (json) parameters, but no query parameters.
type WithBodyResponseProcessor ¶
type WithBodyResponseProcessor struct { }
type WithoutBodyBuilder ¶
type WithoutBodyBuilder struct {
Logger Logger
}
WithoutBodyBuilder supports GET/DELETE methods. It only builds path and query parameters.
type WithoutBodyResponseProcessor ¶
type WithoutBodyResponseProcessor struct { }