Documentation ¶
Index ¶
- Constants
- Variables
- func JsonBodyParser(buf io.Reader, bodyPtr any) (err error)
- func TextBodyParser(buf io.Reader, bodyPtr any) (err error)
- type BodyParser
- type Client
- func (c *Client) Delete(url string, options ...ReqOption) (res *Response, err error)
- func (c *Client) Do(method string, url *url.URL, options ...ReqOption) (res *Response, err error)
- func (c *Client) Get(url string, options ...ReqOption) (res *Response, err error)
- func (c *Client) Head(url string, options ...ReqOption) (res *Response, err error)
- func (c *Client) Options(url string, options ...ReqOption) (res *Response, err error)
- func (c *Client) Post(url string, options ...ReqOption) (res *Response, err error)
- func (c *Client) Put(url string, options ...ReqOption) (res *Response, err error)
- type ClientOption
- type Marshaller
- type ReqOption
- func WithBodyParser(contentType string, bodyParser BodyParser) ReqOption
- func WithBuffer(contentType string, body *bytes.Buffer) ReqOption
- func WithBytes(contentType string, body []byte) ReqOption
- func WithFormData(fields map[string]string) ReqOption
- func WithHeader(key, value string) ReqOption
- func WithHeaders(headers map[string]string) ReqOption
- func WithJsonObject(obj any) ReqOption
- func WithJsonString(json string) ReqOption
- func WithMarshalObject(contentType string, obj any, marshaller Marshaller) ReqOption
- func WithMultipartFile(fieldName string, file *os.File) ReqOption
- func WithMultipartReader(fieldName string, filename string, reader io.Reader) ReqOption
- func WithPath(path string) ReqOption
- func WithQueries(queries map[string][]string) ReqOption
- func WithQuery(key, value string) ReqOption
- func WithString(contentType string, body string) ReqOption
- type Request
- type Response
Constants ¶
View Source
const (
DefaultTimeout = 10 * time.Second
)
Variables ¶
View Source
var BodyParsers = map[string]BodyParser{ "text/plain": TextBodyParser, "application/json": JsonBodyParser, }
View Source
var DefaultClient = NewClient()
Functions ¶
func JsonBodyParser ¶
JsonBodyParser parses application/json content type
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(options ...ClientOption) *Client
type ClientOption ¶
type ClientOption func(clientOptions *clientOptions)
func WithDefaultBodyParser ¶ added in v0.4.0
func WithDefaultBodyParser(contentType string, parser BodyParser) ClientOption
func WithDefaultHeaders ¶ added in v0.2.0
func WithDefaultHeaders(headers map[string][]string) ClientOption
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
type Marshaller ¶ added in v0.4.0
type ReqOption ¶
func WithBodyParser ¶ added in v0.3.0
func WithBodyParser(contentType string, bodyParser BodyParser) ReqOption
WithBodyParser sets ResponseBodyParser
func WithFormData ¶
func WithHeader ¶
func WithHeaders ¶
func WithJsonObject ¶
func WithJsonString ¶
func WithMarshalObject ¶ added in v0.4.0
func WithMarshalObject(contentType string, obj any, marshaller Marshaller) ReqOption
func WithMultipartReader ¶
func WithQueries ¶
func WithString ¶
type Response ¶
func (*Response) BufferedReader ¶
BufferedReader returns the reader for body [Close] will close the body
func (*Response) StatusCode ¶
Click to show internal directories.
Click to hide internal directories.