vendor: update all dependencies
This commit is contained in:
parent
d1a39dcc4b
commit
af192d2507
232 changed files with 15744 additions and 1710 deletions
38
vendor/github.com/koofr/go-httpclient/httpclient.go
generated
vendored
38
vendor/github.com/koofr/go-httpclient/httpclient.go
generated
vendored
|
@ -17,11 +17,15 @@ import (
|
|||
|
||||
var XmlHeaderBytes []byte = []byte(xml.Header)
|
||||
|
||||
type ErrorHandlerFunc func(*http.Response, error) error
|
||||
type PostHookFunc func(*http.Request, *http.Response) error
|
||||
|
||||
type HTTPClient struct {
|
||||
BaseURL *url.URL
|
||||
Headers http.Header
|
||||
Client *http.Client
|
||||
PostHooks map[int]func(*http.Request, *http.Response) error
|
||||
PostHooks map[int]PostHookFunc
|
||||
errorHandler ErrorHandlerFunc
|
||||
rateLimited bool
|
||||
rateLimitChan chan struct{}
|
||||
rateLimitTimeout time.Duration
|
||||
|
@ -31,7 +35,7 @@ func New() (httpClient *HTTPClient) {
|
|||
return &HTTPClient{
|
||||
Client: HttpClient,
|
||||
Headers: make(http.Header),
|
||||
PostHooks: make(map[int]func(*http.Request, *http.Response) error),
|
||||
PostHooks: make(map[int]PostHookFunc),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,10 +47,14 @@ func Insecure() (httpClient *HTTPClient) {
|
|||
|
||||
var DefaultClient = New()
|
||||
|
||||
func (c *HTTPClient) SetPostHook(onStatus int, hook func(*http.Request, *http.Response) error) {
|
||||
func (c *HTTPClient) SetPostHook(onStatus int, hook PostHookFunc) {
|
||||
c.PostHooks[onStatus] = hook
|
||||
}
|
||||
|
||||
func (c *HTTPClient) SetErrorHandler(handler ErrorHandlerFunc) {
|
||||
c.errorHandler = handler
|
||||
}
|
||||
|
||||
func (c *HTTPClient) SetRateLimit(limit int, timeout time.Duration) {
|
||||
c.rateLimited = true
|
||||
c.rateLimitChan = make(chan struct{}, limit)
|
||||
|
@ -279,6 +287,10 @@ func (c *HTTPClient) Request(req *RequestData) (response *http.Response, err err
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if req.Context != nil {
|
||||
r = r.WithContext(req.Context)
|
||||
}
|
||||
|
||||
r.ContentLength = req.ReqContentLength
|
||||
|
||||
if req.FullURL == "" {
|
||||
|
@ -325,15 +337,27 @@ func (c *HTTPClient) Request(req *RequestData) (response *http.Response, err err
|
|||
response, err = c.Client.Do(r)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if req.Context != nil {
|
||||
// If we got an error, and the context has been canceled,
|
||||
// the context's error is probably more useful.
|
||||
select {
|
||||
case <-req.Context.Done():
|
||||
err = req.Context.Err()
|
||||
default:
|
||||
}
|
||||
}
|
||||
if c.errorHandler != nil {
|
||||
err = c.errorHandler(response, err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if isTraceEnabled {
|
||||
responseBytes, _ := httputil.DumpResponse(response, true)
|
||||
fmt.Println(string(responseBytes))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
if err = c.runPostHook(r, response); err != nil {
|
||||
return response, err
|
||||
}
|
||||
|
|
2
vendor/github.com/koofr/go-httpclient/requestdata.go
generated
vendored
2
vendor/github.com/koofr/go-httpclient/requestdata.go
generated
vendored
|
@ -1,6 +1,7 @@
|
|||
package httpclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -15,6 +16,7 @@ const (
|
|||
)
|
||||
|
||||
type RequestData struct {
|
||||
Context context.Context
|
||||
Method string
|
||||
Path string
|
||||
Params url.Values
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue