Documentation ¶
Overview ¶
Package dc client with decoder
Index ¶
- Variables
- type Client
- type Option
- func WithDecoder(decoder decoder.Decoder) Option
- func WithErrorMiddleware(minStatusCode int, errFactory func() error, ...) Option
- func WithFetchMiddleware(mw ...func(*http.Response, io.Reader) error) Option
- func WithHTTPClient(cl *http.Client) Option
- func WithHTTPErrorMiddleware(minStatusCode int, errFactory func(r *http.Response) error, ...) Option
- func WithMiddleware(mw ...transport.Middleware) Option
- func WithTransport(tr http.RoundTripper) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrEmptyBody = errors.New("empty body")
)
ErrEmptyBody base errors
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client get response and marshaling it by decoder
func Must ¶
Must create client or panic
Example ¶
req, _ := http.NewRequest(http.MethodGet, "/api?action=search&q=httpclient", nil) var res struct { Query string Hits []struct { Name string Package string Author string } } err := Must("https://go-search.org").Do(req, &res) if err != nil { log.Fatal(err) } log.Print(res)
Output:
func New ¶
New create new Client with default http client
Example ¶
c, err := New("https://go-search.org") if err != nil { log.Fatal(err) } req, _ := http.NewRequest(http.MethodGet, "/api?action=search&q=httpclient", nil) var res struct { Query string Hits []struct { Name string Package string Author string } } err = c.Do(req, &res) if err != nil { log.Fatal(err) } log.Print(res)
Output:
type Option ¶
type Option func(*Client)
Option for the configure Client
func WithErrorMiddleware ¶
func WithErrorMiddleware(minStatusCode int, errFactory func() error, decoder func(*http.Response, io.Reader, interface{}) error) Option
WithErrorMiddleware add middleware for transport nolint: bodyclose deprecated: use WithHttpErrorMiddleware
func WithFetchMiddleware ¶
WithFetchMiddleware add middleware for transport nolint: bodyclose
func WithHTTPErrorMiddleware ¶ added in v0.0.2
func WithHTTPErrorMiddleware(minStatusCode int, errFactory func(r *http.Response) error, decoder func(*http.Response, io.Reader, interface{}) error) Option
WithHttpErrorMiddleware add middleware for transport nolint: bodyclose
func WithMiddleware ¶
func WithMiddleware(mw ...transport.Middleware) Option
WithMiddleware add middleware do request
Click to show internal directories.
Click to hide internal directories.