-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.go
More file actions
35 lines (30 loc) · 1.05 KB
/
interfaces.go
File metadata and controls
35 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package fetch
import (
"io"
"net/http"
"time"
)
// client - basic http client with retry
type client interface {
Get(url string, headers map[string]string) (resp *http.Response, err error)
Post(url string, body io.Reader, headers map[string]string) (resp *http.Response, err error)
Put(url string, body io.Reader, headers map[string]string) (resp *http.Response, err error)
Patch(url string, body io.Reader, headers map[string]string) (resp *http.Response, err error)
Delete(url string, body io.Reader, headers map[string]string) (resp *http.Response, err error)
}
// httpClient - client interface
type httpClient interface {
Do(req *http.Request) (*http.Response, error)
Get(url string) (resp *http.Response, err error)
Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
}
type Client struct {
// Retry backoff strategy.
// Default is 1s,3s,5s,10s
RetryStrategy []time.Duration
// HTTP client
Client httpClient
// Headers to be added to each request
DefaultHeaders map[string]string
}
var _ client = (*Client)(nil)