-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_walker.go
More file actions
35 lines (27 loc) · 741 Bytes
/
api_walker.go
File metadata and controls
35 lines (27 loc) · 741 Bytes
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 walker
import (
"net/http"
)
type RequestBuilder func(start, fetchCount int) (*http.Request, error)
type httpDataSource struct {
client *http.Client
requestBuilder RequestBuilder
}
func (h *httpDataSource) Fetch(start, fetchCount int) (*http.Response, error) {
req, err := h.requestBuilder(start, fetchCount)
if err != nil {
return nil, err
}
res, err := h.client.Do(req)
if err != nil {
return nil, err
}
return res, nil
}
func NewApiWalker(client *http.Client, requestBuilder RequestBuilder, sink Sink[*http.Response], options ...Option) *Walker[*http.Response] {
source := &httpDataSource{
requestBuilder: requestBuilder,
client: client,
}
return New(source.Fetch, sink, options...)
}