-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopts.go
47 lines (38 loc) · 876 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
42
43
44
45
46
47
package fourbyte
import (
"strconv"
)
type filterOption interface {
apply(*request)
}
type funcFilterOption struct {
f func(*request)
}
func (ffo *funcFilterOption) apply(to *request) {
ffo.f(to)
}
func newFuncFilterOption(f func(*request)) *funcFilterOption {
return &funcFilterOption{
f: f,
}
}
func WithPageNumber(num int) filterOption {
return newFuncFilterOption(func(r *request) {
r.setQueryValue("page", strconv.Itoa(num))
})
}
func WithHexSignature(hex string) filterOption {
return newFuncFilterOption(func(r *request) {
r.addQueryValue("hex_signature", hex)
})
}
func WithTextSignature(text string) filterOption {
return newFuncFilterOption(func(r *request) {
r.addQueryValue("text_signature", text)
})
}
func withId(id int) filterOption {
return newFuncFilterOption(func(r *request) {
r.url = *r.url.JoinPath(strconv.Itoa(id))
})
}