Documentation ¶
Index ¶
- func DecodeBody(resp *http.Response, out interface{}) error
- func EncodeBody(obj interface{}) (io.Reader, error)
- func NewHttpClient(transport *http.Transport, tlsConf TLSConfig) (*http.Client, error)
- func RequireOK(d time.Duration, resp *http.Response, e error) (time.Duration, *http.Response, error)
- func SetupTLSConfig(tlsConfig *TLSConfig) (*tls.Config, error)
- type Client
- type Config
- type CryptoConfig
- type HttpBasicAuth
- type ICacheClient
- type Request
- func (r *Request) GetHeader(k string) string
- func (r *Request) GetParam(k string) string
- func (r *Request) SetBody(obj interface{}) error
- func (r *Request) SetHeader(k, v string)
- func (r *Request) SetHeaders(headers http.Header)
- func (r *Request) SetParam(k, v string)
- func (r *Request) SetParams(params url.Values)
- func (r *Request) ToHTTP() (*http.Request, error)
- type TLSConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeBody ¶
DecodeBody is used to JSON decode a body
func EncodeBody ¶
EncodeBody is used to encode a request body
func NewHttpClient ¶
NewHttpClient returns an http client configured with the given Transport and TLS config.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a client to the Rest API
func (*Client) DoRequest ¶
DoRequest does an HTTP request.
Once the crypto mode enabled, the response result will be decrypted and verified signature using crypto libary, then the final result will be return to end client.
func (*Client) GetEnterpriseSignParam ¶
func (c *Client) GetEnterpriseSignParam() (*pki.SignatureParam, error)
NewClient returns a new client
func (*Client) NewRequest ¶
NewRequest is used to create a new request
type Config ¶
type Config struct { // Address is the address of the Rest server Address string // Scheme is the URI scheme for the Rest server Scheme string // RouteTag is the route tag used by fabio to discover service RouteTag string // Transport is the Transport to use for the http client. Transport *http.Transport // HttpClient is the client to use. Default will be // used if not provided. HttpClient *http.Client // HttpAuth is the auth info to use for http access. HttpAuth *HttpBasicAuth // Token is used to provide a per-request ACL token // which overrides the agent's default token. Token string // Username is the login username used to get token from Fred service Username string // Secret is the login password encrypted by utils/AES // used to get token from Fred service Secret string // SecretKey is the secret key used to encrypt/decrypt Secret field SecretKey string // ApiKey is the access key for ACL access api ApiKey string // EnterpriseSignParam is enterprise sign parameters EnterpriseSignParam *pki.SignatureParam // CallbackUrl is used to receive asynchronous event notification // which will notify if the request succeeded or failed CallbackUrl string // TLS config TLSConfig TLSConfig // CryptoCfg is used to crypto transation between wasabi and client CryptoCfg *CryptoConfig // CacheClient is used to cache auth token CacheClient ICacheClient // TrusteeKeyPairEnable is used to set the flag of trust key pair, // if you want to trust, set the flag is true. TrusteeKeyPairEnable bool }
Config is used to configure the creation of a client
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a default configuration for the client. By default this will pool and reuse idle connections to Rest. If you have a long-lived client object, this is the desired behavior and should make the most efficient use of the connections to Rest. If you don't reuse a client object , which is not recommended, then you may notice idle connections building up over time. To avoid this, use the DefaultNonPooledConfig() instead.
func DefaultNonPooledConfig ¶
func DefaultNonPooledConfig() *Config
DefaultNonPooledConfig returns a default configuration for the client which does not pool connections. This isn't a recommended configuration because it will reconnect to Rest on every request, but this is useful to avoid the accumulation of idle connections if you make many client objects during the lifetime of your application.
type CryptoConfig ¶
type CryptoConfig struct { // Enable flag of transation mode // true is crypto transation, false is origin transation Enable bool // CertsStorePath path of certificate file CertsStorePath string // EncryptType crypto mothed // 0: ecc, 1: rsa EncryptType crypto.EncryptType // SecurityLevel sets the security level SecurityLevel int // HashAlgorithm hash method // default is "sha256" HashAlgorithm string }
CryptoConfig is used to crypto transation between wasabi and client
type HttpBasicAuth ¶
type HttpBasicAuth struct { // Username to use for HTTP Basic Authentication Username string // Password to use for HTTP Basic Authentication Password string }
HttpBasicAuth is used to authenticate http client with HTTP Basic Authentication
type ICacheClient ¶
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is used to help build up a request
func (*Request) SetBody ¶
SetBody is used to set Request body.
The input 'obj' arg can be '[]byte' type binary data, also it can be structure object. When it is the structure object, it will be converted to binary data as JSON using json.Marshal.
Once the crypto mode enabled, the binary data will be signed and encrypted using crypto libary, then the final result set to the request body.
func (*Request) SetHeaders ¶
SeHeaders is used to add multiple header KV pairs
type TLSConfig ¶
type TLSConfig struct { // Address is the optional address of the Rest server. The port, if any // will be removed from here and this will be set to the ServerName of the // resulting config. Address string // CAFile is the optional path to the CA certificate used for Rest // communication, defaults to the system bundle if not specified. CAFile string // CAPath is the optional path to a directory of CA certificates to use for // Rest communication, defaults to the system bundle if not specified. CAPath string // CertFile is the optional path to the certificate for Rest // communication. If this is set then you need to also set KeyFile. CertFile string // KeyFile is the optional path to the private key for Rest communication. // If this is set then you need to also set CertFile. KeyFile string // InsecureSkipVerify if set to true will disable TLS host verification. InsecureSkipVerify bool }
TLSConfig is used to generate a TLSClientConfig that's useful for talking to Rest using TLS.