goBloomFilter/option.go
2025-05-09 18:07:21 +08:00

46 lines
630 B
Go

package bloomfilter
import (
"errors"
"github.com/redis/go-redis/v9"
)
type Mode int
const (
ModeLocal Mode = iota
ModeRedis
)
type Options struct {
mode Mode
client *redis.Client
key string
}
type Option func(*Options)
func UseLocal() Option {
return func(o *Options) {
o.mode = ModeLocal
}
}
func UseRedis(client *redis.Client, key string) Option {
return func(o *Options) {
o.mode = ModeRedis
o.client = client
o.key = key
}
}
func (o *Options) repairOption() error {
if o.mode == ModeRedis {
if o.client == nil || o.key == "" {
return errors.New("no addr provided")
}
}
return nil
}