-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
64 lines (51 loc) · 1.09 KB
/
options.go
File metadata and controls
64 lines (51 loc) · 1.09 KB
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
package twofa
import (
"context"
)
// Options for func
type Options struct {
// HashFunc interface
HashFunc IHashFunc
// With hash
WithHash bool
// Key name
KeyName string
// With QR
WithQR bool
// Options for implementations of the interface can be stored in a context
Context context.Context
}
// OptionFunc used to initialise
type OptionFunc func(opts *Options)
// NewOptions new options
func NewOptions(optionFunc ...OptionFunc) Options {
opts := Options{
Context: context.Background(),
HashFunc: DefaultHashFunc(),
WithHash: false,
}
for _, f := range optionFunc {
f(&opts)
}
return opts
}
// WithDefaultHashFunc option to configure default hash function (sha1)
func WithDefaultHashFunc() OptionFunc {
return func(o *Options) {
o.WithHash = true
}
}
// WithHashFunc option to configure hash function
func WithHashFunc(hashFunc IHashFunc) OptionFunc {
return func(o *Options) {
o.HashFunc = hashFunc
o.WithHash = true
}
}
// WithQR option to configure QR
func WithQR(name string) OptionFunc {
return func(o *Options) {
o.KeyName = name
o.WithQR = true
}
}