-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
75 lines (62 loc) · 1.72 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ots
import (
"fmt"
"net/url"
"time"
)
// ClientOption client option.
type ClientOption func(*Client)
// WithHTTPClient to set custom HTTP client.
func WithHTTPClient(httpClient HTTPClient) ClientOption {
return func(c *Client) {
c.httpClient = httpClient
}
}
// ShareOption share option.
type ShareOption func(url.Values)
// SharePassphrase share a secret with a passphrase.
func SharePassphrase(passPhrase string) ShareOption {
return func(v url.Values) {
v.Set("passphrase", passPhrase)
}
}
// ShareTTL share a secret with TTL.
func ShareTTL(ttl time.Duration) ShareOption {
return func(v url.Values) {
v.Set("ttl", fmt.Sprintf("%d", int64(ttl.Seconds())))
}
}
// ShareRecipient share a secret and send it to recipient.
func ShareRecipient(recipient string) ShareOption {
return func(v url.Values) {
v.Set("recipient", recipient)
}
}
// GenerateOption generate option.
type GenerateOption func(url.Values)
// GeneratePassphrase generate a secret with a passphrase.
func GeneratePassphrase(passPhrase string) GenerateOption {
return func(v url.Values) {
v.Set("passphrase", passPhrase)
}
}
// GenerateTTL generate a secret with TTL.
func GenerateTTL(ttl time.Duration) GenerateOption {
return func(v url.Values) {
v.Set("ttl", fmt.Sprintf("%d", int64(ttl.Seconds())))
}
}
// GenerateRecipient generate a secret and send it to recipient.
func GenerateRecipient(recipient string) GenerateOption {
return func(v url.Values) {
v.Set("recipient", recipient)
}
}
// SecretOption secret option.
type SecretOption func(url.Values)
// SecretPassphrase set a passphrase to receive a secret.
func SecretPassphrase(passPhrase string) SecretOption {
return func(v url.Values) {
v.Set("passphrase", passPhrase)
}
}