Documentation
¶
Index ¶
- Variables
- type CEDResponseWrapper
- type Client
- func (c *Client) DoRequest(ctx context.Context, req *Request) (resp *Response, err error)
- func (c *Client) Get(ctx context.Context, uri string, query ...map[string]string) (resp *Response, err error)
- func (c *Client) Post(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)
- func (c *Client) PostForm(ctx context.Context, url string, form url.Values) (*Response, error)
- func (c *Client) PostJSON(ctx context.Context, url string, body interface{}) (*Response, error)
- func (c *Client) SetHost(host string) *Client
- func (c *Client) SetHostGetter(hg HostGetter) *Client
- type HasData
- type HostGetter
- type Request
- func (r *Request) Body(contentType string, body io.Reader) *Request
- func (r *Request) Build(ctx context.Context) (*http.Request, error)
- func (r *Request) Do(ctx context.Context, clients ...*http.Client) (resp *Response, err error)
- func (r *Request) Form(form url.Values) *Request
- func (r *Request) Header(key, value string) *Request
- func (r *Request) JSON(body interface{}) *Request
- func (r *Request) JSONOrError(body interface{}) (*Request, error)
- type Response
- func (r *Response) Bytes() (bytes []byte, err error)
- func (r *Response) String() (string, error)
- func (r *Response) To(v interface{}) error
- func (r *Response) ToInterface() (interface{}, error)
- func (r *Response) UnwrapTo(w ResponseWrapper, v interface{}) error
- func (r *Response) UnwrapToInterface(w ResponseWrapper) (interface{}, error)
- type ResponseWrapper
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Unmarshalers = map[string]func([]byte, interface{}) error{ `application/json`: JsonUnmarshaler, `application/xml`: XmlUnmarshaler, } DefaultUnmarshaler = JsonUnmarshaler JsonUnmarshaler = func(data []byte, v interface{}) error { return json.Unmarshal(data, v) } XmlUnmarshaler = func(data []byte, v interface{}) error { return xml.Unmarshal(data, v) } )
View Source
var Default = NewClient()
View Source
var (
DefaultHttpClient = &http.Client{Timeout: 15 * time.Second}
)
Functions ¶
This section is empty.
Types ¶
type CEDResponseWrapper ¶
type CEDResponseWrapper struct { Code int `json:"code,omitempty"` ErrMsg string `json:"err_msg,omitempty"` HasData }
func (*CEDResponseWrapper) Error ¶
func (ced *CEDResponseWrapper) Error() error
type Client ¶
func (*Client) SetHostGetter ¶
func (c *Client) SetHostGetter(hg HostGetter) *Client
type HostGetter ¶
type HostGetter func() string
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is builder for http.Request
func (*Request) JSONOrError ¶
JSONOrError set body with application/json return error when marshal failed
type Response ¶
func (*Response) ToInterface ¶
func (*Response) UnwrapTo ¶
func (r *Response) UnwrapTo(w ResponseWrapper, v interface{}) error
func (*Response) UnwrapToInterface ¶
func (r *Response) UnwrapToInterface(w ResponseWrapper) (interface{}, error)
type ResponseWrapper ¶
type ResponseWrapper interface { Error() error SetData(interface{}) GetData() interface{} }
see wrapper_test.go
Click to show internal directories.
Click to hide internal directories.