-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
101 lines (86 loc) · 1.88 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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package auth
import (
"hash"
"time"
"github.com/yaitoo/sqle/shardid"
)
type Option func(a *Auth)
// WithPrefix add prefix for auth tables
func WithPrefix(prefix string) Option {
return func(a *Auth) {
a.prefix = prefix
}
}
// WithGenUser set custom shardid generator for user id
func WithGenUser(gen *shardid.Generator) Option {
return func(a *Auth) {
a.genUser = gen
}
}
// WithGenLogin set custom shardid generator for login id
func WithGenLogin(gen *shardid.Generator) Option {
return func(a *Auth) {
a.genLoginLog = gen
}
}
// WithGenAuditLog set custom shardid generator for audit log id
func WithGenAuditLog(gen *shardid.Generator) Option {
return func(a *Auth) {
a.genUser = gen
}
}
// WithHash set custom hash
func WithHash(h func() hash.Hash) Option {
return func(a *Auth) {
a.hash = h
}
}
// WithAES setup AES key
func WithAES(key string) Option {
return func(a *Auth) {
a.aesKey = getAESKey(key)
}
}
// WithAccessTokenTTL setup ttl for access token
func WithAccessTokenTTL(d time.Duration) Option {
return func(a *Auth) {
if d > 0 {
a.accessTokenTTL = d
}
}
}
// WithRefreshTokenTTL setup ttl for refresh token
func WithRefreshTokenTTL(d time.Duration) Option {
return func(a *Auth) {
if d > 0 {
a.refreshTokenTTL = d
}
}
}
// WithJWT setup jwt signature key
func WithJWT(signKey string) Option {
return func(a *Auth) {
a.jwtSignKey = getJWTKey(signKey)
}
}
// WithTOTP setup totp options
func WithTOTP(issuer, accountName string) Option {
return func(a *Auth) {
a.totpIssuer = issuer
a.totpAccountName = accountName
}
}
// WithDHT setup dht names
func WithDHT(email, mobile string) Option {
return func(a *Auth) {
a.dhtEmail = email
a.dhtMobile = mobile
}
}
// WithLoginCode set sign in code length and ttl
func WithLoginCode(size int, ttl time.Duration) Option {
return func(a *Auth) {
a.loginCodeSize = size
a.loginCodeTTL = ttl
}
}