-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
61 lines (51 loc) · 1.25 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
package recaptcha
import (
"net/http"
)
// Option describes a functional parameter for the New constructor.
type Option func(*Recaptcha) error
// WithHTTPClient allows for overriding of the http client.
func WithHTTPClient(client *http.Client) Option {
return func(rec *Recaptcha) error {
if client == nil {
return errNilClient
}
rec.client = client
return nil
}
}
// WithVersion allows for overriding of the reCaptcha version.
// Default value is 3.
func WithVersion(version int) Option {
return func(rec *Recaptcha) error {
if version != 2 && version != 3 {
return errInvalidVersion
}
rec.version = version
return nil
}
}
// WithAction allows for overriding of the reCaptcha action.
// Default value is empty string.
// Only applicable for reCaptcha V3.
func WithAction(action string) Option {
return func(rec *Recaptcha) error {
if action == "" {
return errInvalidAction
}
rec.action = action
return nil
}
}
// WithScore allows for overriding of the minimum reCaptcha accepted score.
// Default value is 0.5.
// Only applicable for reCaptcha V3.
func WithScore(score float64) Option {
return func(rec *Recaptcha) error {
if score < 0.0 || score > 1.0 {
return errInvalidScore
}
rec.score = score
return nil
}
}