Documentation ¶
Index ¶
- Constants
- Variables
- 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 XClient
- func (client *XClient) Auth() bool
- 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) GetSignedWithHeaders(url string, headers map[string]string) (*http.Response, error)
- func (client *XClient) OffAuth() Client
- func (client *XClient) OnAuth() Client
- 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, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) PostJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) PostSignedWithHeaders(url string, data interface{}, headers map[string]string) (*http.Response, error)
- func (client *XClient) PublicKey() crypto.Key
- func (client *XClient) PutJSON(url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) RemoveDefaultCookies() Client
- func (client *XClient) RemoveDefaultHeaders() Client
- func (client *XClient) RequestJSON(method string, url string, bodyStruct interface{}, headers Headers) (*http.Response, error)
- func (client *XClient) Service() string
- func (client *XClient) SetAuth(service string, kp crypto.KP) Client
- func (client *XClient) SetDefaultCookies(cookies []*http.Cookie) Client
- func (client *XClient) SetDefaultHeaders(headers Headers) Client
- func (client *XClient) SetHeader(key, val string) Client
- func (client *XClient) SetLogger(l log.Entry)
- func (client *XClient) SignRequest(req *http.Request, body []byte, headers map[string]string) (*http.Request, error)
- func (client *XClient) VerifyBody(r *http.Request, body []byte) (bool, error)
- func (client *XClient) VerifyRequest(r *http.Request, publicKey string) (bool, error)
- 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" HeaderPassHeaders = "X-Custom-Headers" )
Variables ¶
var DefaultXClient = NewXClient()
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 { CookiesSupport CustomHeadersSupport JSONClient // Auth returns current state of authentication flag. Auth() bool // OnAuth disables request authentication. OffAuth() Client // OnAuth enables request authentication. OnAuth() Client // 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) Client // 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) }
Client is a interface of extended http.Client which support signed request.
func WithCookies ¶
WithCookies returns default client with cookies.
type CookiesSupport ¶
type CookiesSupport interface { // DefaultCookies returns a client's default cookies. DefaultCookies() []*http.Cookie // SetCookies 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 XClient ¶
func NewXClient ¶
func NewXClient() *XClient
func SetTimeout ¶
SetTimeout updated `DefaultXClient` default timeout (15s).
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) GetSignedWithHeaders ¶
func (client *XClient) GetSignedWithHeaders(url string, headers map[string]string) (*http.Response, error)
PostSignedWithHeaders create new signed GET request with headers
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, bodyStruct 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, bodyStruct interface{}, headers Headers) (*http.Response, error)
PostJSON, sets passed `headers` and `body` and executes RequestJSON with POST method.
func (*XClient) PostSignedWithHeaders ¶
func (client *XClient) PostSignedWithHeaders(url string, data interface{}, headers map[string]string) (*http.Response, error)
PostSignedWithHeaders create new POST signed request with headers
func (*XClient) PutJSON ¶
func (client *XClient) PutJSON(url string, bodyStruct 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, bodyStruct interface{}, headers Headers) (*http.Response, error)
RequestJSON creates and executes new request with JSON content type.
func (*XClient) SetDefaultCookies ¶
SetCookies sets a default cookies to the client.
func (*XClient) SetDefaultHeaders ¶
SetDefaultHeaders sets a default headers to the client.
func (*XClient) SignRequest ¶
func (client *XClient) 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 (*XClient) VerifyBody ¶
VerifyBody checks the request body match with it hash.
func (*XClient) VerifyRequest ¶
VerifyRequest checks the request auth headers.
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.