2023-01-30 21:06:18 +00:00
|
|
|
package gapr
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2023-01-31 20:14:34 +00:00
|
|
|
func WithRandomSeed(i int64) optionFunc {
|
|
|
|
return func(o *options) {
|
2023-01-30 21:06:18 +00:00
|
|
|
o.RandomSeed = i
|
2023-01-31 20:14:34 +00:00
|
|
|
}
|
2023-01-30 21:06:18 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 20:14:34 +00:00
|
|
|
func WithTagName(tag string) optionFunc {
|
|
|
|
return func(o *options) {
|
2023-01-30 21:06:18 +00:00
|
|
|
o.TagName = tag
|
2023-01-31 20:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMapper(mapper KeyMapper) optionFunc {
|
|
|
|
return func(o *options) {
|
|
|
|
o.Mapper = mapper
|
|
|
|
}
|
2023-01-30 21:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultOptions() options {
|
|
|
|
return options{
|
|
|
|
TagName: "gapr",
|
|
|
|
RandomSeed: time.Now().UTC().Unix(),
|
2023-01-31 20:14:34 +00:00
|
|
|
Mapper: identityKeyMapper,
|
2023-01-30 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option interface {
|
|
|
|
apply(o *options)
|
|
|
|
}
|
|
|
|
|
|
|
|
type optionFunc func(o *options)
|
|
|
|
|
|
|
|
func (f optionFunc) apply(o *options) {
|
|
|
|
f(o)
|
|
|
|
}
|
|
|
|
|
|
|
|
type options struct {
|
|
|
|
TagName string
|
|
|
|
RandomSeed int64
|
2023-01-31 20:14:34 +00:00
|
|
|
Mapper KeyMapper
|
2023-01-30 21:06:18 +00:00
|
|
|
}
|