Documentation
¶
Index ¶
- Variables
- func IsJSON(ct string) bool
- func Unmarshal(ct string, b []byte, d interface{}) error
- type Client
- type ClientOptions
- type Header
- type Option
- type Params
- type Query
- type Request
- func (r *Request) Execute(ctx context.Context, method, path string) (*Response, error)
- func (r *Request) SetBody(body any) *Request
- func (r *Request) SetContentLength(length int64) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaders(header Header) *Request
- func (r *Request) SetParams(params Params) *Request
- func (r *Request) SetQuery(query Query) *Request
- type Response
- func (r *Response) Body() []byte
- func (r *Response) ContentLength() int64
- func (r *Response) Header() http.Header
- func (r *Response) IsError() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) RawBody() io.ReadCloser
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
- func (r *Response) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrClientMissing = errors.New("use .NR() to create a new request instead")
ErrClientMissing occurs when Request is instantiated without Client.NR()
Functions ¶
Types ¶
type Client ¶
type Client struct {
Header Header
// contains filtered or unexported fields
}
Client wraps an http client.
type ClientOptions ¶
ClientOptions to configure the http client.
type Option ¶ added in v0.2.0
type Option func(*Client)
Option to use in option pattern.
func WithCookieJar ¶ added in v0.7.2
WithCookieJar sets a cookie jar on rips httpClient.
func WithDefaultHeaders ¶ added in v0.2.0
WithDefaultHeaders sets client default headers (e.g. x-api-key)
func WithTimeout ¶ added in v0.2.0
WithTimeout sets timeout in seconds on rips httpClient.
func WithTransport ¶ added in v0.7.5
WithTransport sets a custom Transport.
type Request ¶
type Request struct {
Body any
Header http.Header
Params Params
Path string
ContentLength int64
Query url.Values
Result any // NOTE: can I pass struct here to unmarshal resp body to?
URL string
// contains filtered or unexported fields
}
Request is the RIP request.
func (*Request) SetContentLength ¶ added in v0.7.4
SetContentLength for when you want to overwrite the default behaviour of *http.Request to calculate Content-Length. see: https://pkg.go.dev/net/http#NewRequestWithContext
func (*Request) SetHeaders ¶
SetHeaders to set multiple header as map[string]string
type Response ¶
type Response struct {
Request *Request
Close func() error
// contains filtered or unexported fields
}
Response the rip response wrapping the original request and response.
func NewResponse ¶ added in v0.7.1
func (*Response) ContentLength ¶ added in v0.3.1
ContentLength returns the content-length.
func (*Response) RawBody ¶
func (r *Response) RawBody() io.ReadCloser
RawBody returns raw response body. be sure to close
func (*Response) StatusCode ¶
StatusCode returns the response status code.