45 lines
677 B
Go
45 lines
677 B
Go
package gapr
|
|
|
|
import "time"
|
|
|
|
func WithRandomSeed(i int64) optionFunc {
|
|
return func(o *options) {
|
|
o.RandomSeed = i
|
|
}
|
|
}
|
|
|
|
func WithTagName(tag string) optionFunc {
|
|
return func(o *options) {
|
|
o.TagName = tag
|
|
}
|
|
}
|
|
|
|
func WithMapper(mapper KeyMapper) optionFunc {
|
|
return func(o *options) {
|
|
o.Mapper = mapper
|
|
}
|
|
}
|
|
|
|
func defaultOptions() options {
|
|
return options{
|
|
TagName: "gapr",
|
|
RandomSeed: time.Now().UTC().Unix(),
|
|
Mapper: identityKeyMapper,
|
|
}
|
|
}
|
|
|
|
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
|
|
Mapper KeyMapper
|
|
}
|