-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
79 lines (62 loc) · 1.38 KB
/
options.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package archiver
import (
"github.com/aholstenson/webpage-archiver/pkg/progress"
)
type archiverConfig struct {
reporter progress.Reporter
userAgent string
}
type captureConfig struct {
reporter progress.Reporter
userAgent string
screenshotFunc func([]byte) error
}
type Option interface {
applyArchiver(o *archiverConfig)
}
type CaptureOption interface {
applyCapture(o *captureConfig)
}
type SharedOption interface {
Option
CaptureOption
}
type reporterOption struct {
reporter progress.Reporter
}
func (o *reporterOption) applyArchiver(c *archiverConfig) {
c.reporter = o.reporter
}
func (o *reporterOption) applyCapture(c *captureConfig) {
c.reporter = o.reporter
}
func WithReporter(reporter progress.Reporter) SharedOption {
return &reporterOption{
reporter: reporter,
}
}
type userAgentOption struct {
userAgent string
}
func (o *userAgentOption) applyArchiver(c *archiverConfig) {
c.userAgent = o.userAgent
}
func (o *userAgentOption) applyCapture(c *captureConfig) {
c.userAgent = o.userAgent
}
func WithUserAgent(ua string) SharedOption {
return &userAgentOption{
userAgent: ua,
}
}
type screenshotOption struct {
f func([]byte) error
}
func (o *screenshotOption) applyCapture(c *captureConfig) {
c.screenshotFunc = o.f
}
func WithScreenshot(screenshotFunc func([]byte) error) CaptureOption {
return &screenshotOption{
f: screenshotFunc,
}
}