forked from getlantern/flashlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
44 lines (37 loc) · 1.39 KB
/
option.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
package flashlight
import (
"github.com/getlantern/flashlight/v7/config"
"github.com/getlantern/flashlight/v7/dialer"
)
type Option func(*Flashlight)
// WithOnSucceedingProxy sets the onSucceedingProxy callback
func WithOnSucceedingProxy(onSucceedingProxy func()) Option {
return func(client *Flashlight) {
client.callbacks.onSucceedingProxy = onSucceedingProxy
}
}
// WithOnConfig sets the callback that is called when a config is successfully fetched
func WithOnConfig(onConfigUpdate func(*config.Global, config.Source)) Option {
return func(client *Flashlight) {
client.callbacks.onConfigUpdate = onConfigUpdate
}
}
// WithOnDialError sets the callback that is called when an error occurs dialing a proxy. It includes the error itself and whether or not we
// have any successful dialers
func WithOnDialError(onDialError func(error, bool)) Option {
return func(client *Flashlight) {
client.callbacks.onDialError = onDialError
}
}
// WithInit sets the callback that is called when flashlight is ready and has a config or needs to be initialized
func WithInit(onInit func()) Option {
return func(client *Flashlight) {
client.callbacks.onInit = onInit
}
}
// WithOnProxies sets the callback when new proxies are received
func WithOnProxies(onProxiesUpdate func([]dialer.ProxyDialer, config.Source)) Option {
return func(client *Flashlight) {
client.callbacks.onProxiesUpdate = onProxiesUpdate
}
}