-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_store_option.go
45 lines (37 loc) · 1.16 KB
/
token_store_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
45
package hcstore
import "github.com/pkg/errors"
// TokenStoreOption is a function that can be used to modify behavior of the `tokenStore`.
type TokenStoreOption func(ts *tokenStore) error
// WithAccessMapName sets the name of the map that is used to save access tokens. An error is returned
// if the name is empty.
func WithAccessMapName(name string) TokenStoreOption {
return func(ts *tokenStore) error {
if name == "" {
return errors.New("invalid access map name")
}
ts.accessMapName = name
return nil
}
}
// WithRefreshMapName sets the name of the map that is used to save refresh tokens. An error is returned
// if the name is empty.
func WithRefreshMapName(name string) TokenStoreOption {
return func(ts *tokenStore) error {
if name == "" {
return errors.New("invalid refresh map name")
}
ts.refreshMapName = name
return nil
}
}
// WithCodesMapName sets the name of the map that is used to save codes. An error is returned if the name
// is empty.
func WithCodesMapName(name string) TokenStoreOption {
return func(ts *tokenStore) error {
if name == "" {
return errors.New("invalid code map name")
}
ts.codeMapName = name
return nil
}
}