Documentation
¶
Index ¶
- Constants
- func DeleteJSON(url string, headers map[string]string) (*http.Response, error)
- func GetJSON(url string, headers map[string]string) (*http.Response, error)
- func ParseJSONBody(r *http.Request, dest interface{}) error
- func ParseJSONResult(httpResp *http.Response, dest interface{}) error
- func PostJSON(url string, body interface{}, headers map[string]string) (*http.Response, error)
- func PutJSON(url string, body interface{}, headers map[string]string) (*http.Response, error)
- func RequestJSON(method string, url string, data interface{}, headers map[string]string) (*http.Response, error)
- type Client
- type CookiesSupport
- type CustomHeadersSupport
- type Headers
- type JSONClient
- type SXClient
- func (client *SXClient) Auth() bool
- func (client *SXClient) CloneWAuth() SecuredClient
- func (client *SXClient) DeleteJSON(url string, headers Headers) (*http.Response, error)
- func (client *SXClient) GetJSON(url string, headers Headers) (*http.Response, error)
- func (client *SXClient) GetSignedWithHeaders(url string, headers map[string]string) (*http.Response, error)
- func (client *SXClient) OffAuth() SecuredClient
- func (client *SXClient) OnAuth() SecuredClient
- func (client *SXClient) PatchJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *SXClient) PostJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *SXClient) PostSignedWithHeaders(url string, data interface{}, headers map[string]string) (*http.Response, error)
- func (client *SXClient) PublicKey() crypto.Key
- func (client *SXClient) PutJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *SXClient) RequestJSON(method string, url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *SXClient) Service() string
- func (client *SXClient) SetAuth(service string, kp crypto.KP) SecuredClient
- func (client *SXClient) SignRequest(req *http.Request, body []byte, headers map[string]string) (*http.Request, error)
- func (client *SXClient) VerifyBody(r *http.Request, body []byte) (bool, error)
- func (client *SXClient) VerifyRequest(r *http.Request, publicKey string) (bool, error)
- type SecuredClient
- type XClient
- func (client *XClient) Clone() Client
- func (client *XClient) DefaultCookies() []*http.Cookie
- func (client *XClient) DefaultHeaders() Headers
- func (client *XClient) DeleteJSON(url string, headers Headers) (*http.Response, error)
- func (client *XClient) GetJSON(url string, headers Headers) (*http.Response, error)
- func (client *XClient) ParseJSONBody(r *http.Request, dest interface{}) error
- func (client *XClient) ParseJSONResult(httpResp *http.Response, dest interface{}) error
- func (client *XClient) PatchJSON(url string, body interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) PostJSON(url string, body interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) PutJSON(url string, body interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) RemoveDefaultCookies() Client
- func (client *XClient) RemoveDefaultHeaders() Client
- func (client *XClient) RequestJSON(method string, url string, body interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) SetDefaultCookies(cookies []*http.Cookie) Client
- func (client *XClient) SetDefaultHeaders(headers Headers) Client
- func (client *XClient) SetHTTP(hc http.Client) Client
- func (client *XClient) SetHeader(key, val string) Client
- func (client *XClient) SetLogger(logger *logrus.Entry) Client
- func (client *XClient) WithCookies(cookies []*http.Cookie) Client
- func (client *XClient) WithHeaders(headers Headers) Client
Constants ¶
const ( HeaderBodyHash = "X-Auth-BHash" HeaderSignature = "X-Auth-Signature" HeaderSigner = "X-Auth-Signer" HeaderService = "X-Auth-Service" HeaderJWTParsed = "jwt" HeaderHeadersList = "X-Custom-Headers" )
Variables ¶
This section is empty.
Functions ¶
func DeleteJSON ¶
DeleteJSON sets passed `headers` and executes RequestJSON with DELETE method.
func ParseJSONBody ¶
ParseJSONBody decodes `json` body from the `http.Request`.
func ParseJSONResult ¶
ParseJSONResult decodes `json` body from the `http.Response`.
func PostJSON ¶
PostJSON sets passed `headers` and `body` and executes RequestJSON with POST method. Post issues a POST to the specified URL.
Caller should close resp.Body when done reading from it.
If the provided body is an io.Closer, it is closed after the request.
Post is a wrapper around DefaultClient.Post.
To set custom headers, use NewRequest and DefaultClient.Do.
See the Client.Do method documentation for details on how redirects are handled.
Types ¶
type Client ¶
type Client interface {
JSONClient
CookiesSupport
CustomHeadersSupport
// Clone returns safe clone of Client.
Clone() Client
// SetHTTP - Set customized instance of http.Client
SetHTTP(hc http.Client) Client
// SetLogger - Set logger to enable log requests
SetLogger(logger *logrus.Entry) Client
}
Client is an interface of extended http.Client.
func WithCookies ¶
WithCookies returns default client with cookies.
func WithHeaders ¶ added in v1.8.0
WithHeaders append headers to the client and return new instance.
type CookiesSupport ¶
type CookiesSupport interface {
// DefaultCookies returns a client's default cookies.
DefaultCookies() []*http.Cookie
// SetDefaultCookies sets a default cookies to a client.
SetDefaultCookies(cookies []*http.Cookie) Client
// RemoveDefaultCookies removes a default client's cookies.
RemoveDefaultCookies() Client
// WithCookies append cookies to a client and return new instance.
WithCookies(cookies []*http.Cookie) Client
}
type CustomHeadersSupport ¶
type CustomHeadersSupport interface {
// DefaultHeaders returns a client's default headers.
DefaultHeaders() Headers
// SetDefaultHeaders sets a default headers to a client.
SetDefaultHeaders(headers Headers) Client
// SetHeader sets new default header to the client.
SetHeader(key, val string) Client
// RemoveDefaultHeaders removes a default client's headers.
RemoveDefaultHeaders() Client
// WithHeaders append headers to a client and return new instance.
WithHeaders(headers Headers) Client
}
type JSONClient ¶
type JSONClient interface {
// PostJSON sets passed `headers` and `body` and executes RequestJSON with POST method.
PostJSON(url string, body interface{}, headers Headers) (*http.Response, error)
// PatchJSON sets passed `headers` and `body` and executes RequestJSON with PATCH method.
PatchJSON(url string, body interface{}, headers Headers) (*http.Response, error)
// PutJSON sets passed `headers` and `body` and executes RequestJSON with PUT method.
PutJSON(url string, body interface{}, headers Headers) (*http.Response, error)
// GetJSON sets passed `headers` and executes RequestJSON with GET method.
GetJSON(url string, headers Headers) (*http.Response, error)
// DeleteJSON sets passed `headers` and executes RequestJSON with DELETE method.
DeleteJSON(url string, headers Headers) (*http.Response, error)
// RequestJSON creates and executes new request with JSON content type.
RequestJSON(method string, url string, data interface{}, headers Headers) (*http.Response, error)
// ParseJSONBody decodes `json` body from the `http.Request`.
ParseJSONBody(r *http.Request, dest interface{}) error
// ParseJSONResult decodes `json` body from the `http.Response`.
ParseJSONResult(httpResp *http.Response, dest interface{}) error
}
type SXClient ¶ added in v1.8.0
type SXClient struct {
XClient
// contains filtered or unexported fields
}
SXClient implementation of the SecuredClient.
func NewSXClient ¶ added in v1.8.0
func NewSXClient() *SXClient
NewSXClient returns new SecuredClient.
func (*SXClient) CloneWAuth ¶ added in v1.8.0
func (client *SXClient) CloneWAuth() SecuredClient
CloneWAuth returns a safe clone of SecuredClient.
func (*SXClient) DeleteJSON ¶ added in v1.8.0
DeleteJSON sets passed `headers` and executes RequestJSON with DELETE method.
func (*SXClient) GetJSON ¶ added in v1.8.0
GetJSON sets passed `headers` and executes RequestJSON with GET method.
func (*SXClient) GetSignedWithHeaders ¶ added in v1.8.0
func (client *SXClient) GetSignedWithHeaders(url string, headers map[string]string) (*http.Response, error)
GetSignedWithHeaders create new signed GET request with headers
func (*SXClient) OffAuth ¶ added in v1.8.0
func (client *SXClient) OffAuth() SecuredClient
func (*SXClient) OnAuth ¶ added in v1.8.0
func (client *SXClient) OnAuth() SecuredClient
OnAuth enables request authentication.
func (*SXClient) PatchJSON ¶ added in v1.8.0
func (client *SXClient) PatchJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
PatchJSON sets passed `headers` and `body` and executes RequestJSON with PATCH method.
func (*SXClient) PostJSON ¶ added in v1.8.0
func (client *SXClient) PostJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
PostJSON sets passed `headers` and `body` and executes RequestJSON with POST method.
func (*SXClient) PostSignedWithHeaders ¶ added in v1.8.0
func (client *SXClient) PostSignedWithHeaders(url string, data interface{}, headers map[string]string) (*http.Response, error)
PostSignedWithHeaders create new POST signed request with headers
func (*SXClient) PutJSON ¶ added in v1.8.0
func (client *SXClient) PutJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
PutJSON sets passed `headers` and `body` and executes RequestJSON with PUT method.
func (*SXClient) RequestJSON ¶ added in v1.8.0
func (client *SXClient) RequestJSON(method string, url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
RequestJSON creates and executes new request with JSON content type.
func (*SXClient) SetAuth ¶ added in v1.8.0
func (client *SXClient) SetAuth(service string, kp crypto.KP) SecuredClient
SetAuth sets the auth credentials.
func (*SXClient) SignRequest ¶ added in v1.8.0
func (client *SXClient) SignRequest(req *http.Request, body []byte, headers map[string]string) (*http.Request, error)
SignRequest takes body hash, some headers and full URL path, sings this request details using the `client.privateKey` and adds the auth headers.
func (*SXClient) VerifyBody ¶ added in v1.8.0
VerifyBody checks the request body match with it hash.
type SecuredClient ¶ added in v1.8.0
type SecuredClient interface {
Client
// CloneWAuth returns a safe clone of SecuredClient.
CloneWAuth() SecuredClient
// Auth returns current state of authentication flag.
Auth() bool
// OffAuth disables request authentication.
OffAuth() SecuredClient
// OnAuth enables request authentication.
OnAuth() SecuredClient
// PublicKey returns client public key.
PublicKey() crypto.Key
// Service returns auth service name.
Service() string
// SetAuth sets the auth credentials.
SetAuth(service string, kp crypto.KP) SecuredClient
// SignRequest takes body hash, some headers and full URL path,
// sings this request details using the `client.privateKey` and adds the auth headers.
SignRequest(req *http.Request, body []byte, headers map[string]string) (*http.Request, error)
// VerifyBody checks the request body match with it hash.
VerifyBody(r *http.Request, body []byte) (bool, error)
// VerifyRequest checks the request auth headers.
VerifyRequest(r *http.Request, publicKey string) (bool, error)
// PostSignedWithHeaders signs request body and headers by set keys and sends it.
PostSignedWithHeaders(url string, data interface{}, headers map[string]string) (*http.Response, error)
// GetSignedWithHeaders signs request headers by set keys and sends it.
GetSignedWithHeaders(url string, headers map[string]string) (*http.Response, error)
}
SecuredClient is an extension of the Client that adds possibility to sign and verify request.
type XClient ¶
XClient is an implementation of the Client.
func (*XClient) DefaultCookies ¶
DefaultCookies returns a client's default cookies.
func (*XClient) DefaultHeaders ¶
DefaultHeaders returns a client's default headers.
func (*XClient) DeleteJSON ¶
DeleteJSON sets passed `headers` and executes RequestJSON with DELETE method.
func (*XClient) ParseJSONBody ¶
ParseJSONBody decodes `json` body from the `http.Request`. !> `dest` must be a pointer value.
func (*XClient) ParseJSONResult ¶
ParseJSONResult decodes `json` body from the `http.Response` body into `dest` > `dest` must be a pointer value.
func (*XClient) PatchJSON ¶
func (client *XClient) PatchJSON(url string, body interface{}, headers Headers) (*http.Response, error)
PatchJSON sets passed `headers` and `body` and executes RequestJSON with PATCH method.
func (*XClient) PostJSON ¶
func (client *XClient) PostJSON(url string, body interface{}, headers Headers) (*http.Response, error)
PostJSON sets passed `headers` and `body` and executes RequestJSON with POST method.
func (*XClient) PutJSON ¶
func (client *XClient) PutJSON(url string, body interface{}, headers Headers) (*http.Response, error)
PutJSON sets passed `headers` and `body` and executes RequestJSON with PUT method.
func (*XClient) RemoveDefaultCookies ¶
RemoveDefaultCookies removes a default client's cookies.
func (*XClient) RemoveDefaultHeaders ¶
RemoveDefaultHeaders removes a default client's headers.
func (*XClient) RequestJSON ¶
func (client *XClient) RequestJSON(method string, url string, body interface{}, headers Headers) (*http.Response, error)
RequestJSON creates and executes new request with JSON content type.
func (*XClient) SetDefaultCookies ¶
SetDefaultCookies sets a default cookies to the client.
func (*XClient) SetDefaultHeaders ¶
SetDefaultHeaders sets a default headers to the client.
func (*XClient) WithCookies ¶
WithCookies append cookies to the client and return new instance.
func (*XClient) WithHeaders ¶
WithHeaders append headers to the client and return new instance.