-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_option.go
51 lines (41 loc) · 847 Bytes
/
gen_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
package tuid
import "time"
type GenOption interface {
apply(*TUID)
}
type funcGenOption struct {
f func(*TUID)
}
func (fgo *funcGenOption) apply(id *TUID) {
fgo.f(id)
}
func newFuncDialOption(f func(*TUID)) *funcGenOption {
return &funcGenOption{
f: f,
}
}
func WithPrefix(prefix string) GenOption {
return newFuncDialOption(func(id *TUID) {
id.prefix = prefix
})
}
func WithTimeLayout(layout string) GenOption {
return newFuncDialOption(func(id *TUID) {
id.timeLayout = layout
})
}
func WithTime(t time.Time) GenOption {
return newFuncDialOption(func(id *TUID) {
id.time = t
})
}
func WithRandomCode(length int) GenOption {
return newFuncDialOption(func(id *TUID) {
id.randomCode = RandomString(length)
})
}
func WithSequence(seq int64) GenOption {
return newFuncDialOption(func(id *TUID) {
id.seq = seq
})
}