-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
58 lines (49 loc) · 912 Bytes
/
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
package flaresolverr
import (
"context"
"net/http"
"strconv"
"time"
"golang.org/x/time/rate"
)
type Option func(*Client)
func WithProtocol(proto string) Option {
return func(c *Client) {
if proto != "" {
c.proto = proto
}
}
}
func WithPort(port int) Option {
return func(c *Client) {
if port > 0 {
c.port = port
}
}
}
func WithPortString(port string) Option {
p, _ := strconv.Atoi(port)
return WithPort(p)
}
func WithHostName(hostname string) Option {
return func(c *Client) {
if hostname != "" {
c.hostname = hostname
}
}
}
func WithClient(httpclient *http.Client) Option {
return func(c *Client) {
if httpclient != nil {
c.httpClient = httpclient
}
}
}
func WithRate(duration time.Duration, ctx context.Context) Option {
return func(c *Client) {
if duration > 0 {
c.limiter = rate.NewLimiter(rate.Every(duration), 1)
c.limiterContext = ctx
}
}
}