-
Notifications
You must be signed in to change notification settings - Fork 2
/
opts.go
41 lines (33 loc) · 839 Bytes
/
opts.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
package indexer
import "net/http"
type indexerOptions struct {
debug bool
client *http.Client
}
// funcIndexerOption wraps a function that modifies indexerOptions into an
// implementation of the IndexerOption interface.
type funcIndexerOption struct {
f func(*indexerOptions)
}
func (fso *funcIndexerOption) apply(do *indexerOptions) {
fso.f(do)
}
func newFuncIndexerOption(f func(*indexerOptions)) *funcIndexerOption {
return &funcIndexerOption{
f: f,
}
}
// IndexerOption configures how we set up the connection.
type IndexerOption interface {
apply(*indexerOptions)
}
func WithHttpClient(client http.Client) IndexerOption {
return newFuncIndexerOption(func(o *indexerOptions) {
o.client = &client
})
}
func WithDebug() IndexerOption {
return newFuncIndexerOption(func(o *indexerOptions) {
o.debug = true
})
}