-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathservices.go
56 lines (49 loc) · 1.64 KB
/
services.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package scrapemate
import (
"context"
"net/http"
)
// JobProvider is an interface for job providers
// a job provider is a service that provides jobs to scrapemate
// scrapemate will call the job provider to get jobs
//
//go:generate mockgen -destination=mock/mock_provider.go -package=mock . JobProvider
type JobProvider interface {
Jobs(ctx context.Context) (<-chan IJob, <-chan error)
// Push pushes a job to the job provider
Push(ctx context.Context, job IJob) error
}
// HTTPFetcher is an interface for http fetchers
//
//go:generate mockgen -destination=mock/mock_http_fetcher.go -package=mock . HTTPFetcher
type HTTPFetcher interface {
Fetch(ctx context.Context, job IJob) Response
Close() error
}
// HTMLParser is an interface for html parsers
//
//go:generate mockgen -destination=mock/mock_parser.go -package=mock . HTMLParser
type HTMLParser interface {
Parse(ctx context.Context, body []byte) (any, error)
}
// Cacher is an interface for cache
//
//go:generate mockgen -destination=mock/mock_cacher.go -package=mock . Cacher
type Cacher interface {
Close() error
Get(ctx context.Context, key string) (Response, error)
Set(ctx context.Context, key string, value *Response) error
}
// ResultWriter is an interface for result writers
//
//go:generate mockgen -destination=mock/mock_writer.go -package=mock . ResultWriter
type ResultWriter interface {
Run(ctx context.Context, in <-chan Result) error
}
// ProxyRotator is an interface for proxy rotators
//
//go:generate mockgen -destination=mock/mock_proxy_rotator.go -package=mock . ProxyRotator
type ProxyRotator interface {
RoundTrip(req *http.Request) (*http.Response, error)
Next() Proxy
}