micro/sync/options.go

62 lines
961 B
Go
Raw Normal View History

2019-05-31 00:43:23 +01:00
package sync
import (
2020-04-11 10:37:54 +01:00
"time"
"github.com/unistack-org/micro/v3/logger"
2019-05-31 00:43:23 +01:00
)
type Options struct {
Nodes []string
Prefix string
Logger logger.Logger
}
type Option func(o *Options)
type LeaderOptions struct{}
type LeaderOption func(o *LeaderOptions)
type LockOptions struct {
TTL time.Duration
Wait time.Duration
}
type LockOption func(o *LockOptions)
// Logger sets the logger
func Logger(l logger.Logger) Option {
return func(o *Options) {
o.Logger = l
}
}
2020-04-11 10:37:54 +01:00
// Nodes sets the addresses to use
func Nodes(a ...string) Option {
2019-05-31 00:43:23 +01:00
return func(o *Options) {
2020-04-11 10:37:54 +01:00
o.Nodes = a
2019-05-31 00:43:23 +01:00
}
}
2020-04-11 10:37:54 +01:00
// Prefix sets a prefix to any lock ids used
func Prefix(p string) Option {
2019-05-31 00:43:23 +01:00
return func(o *Options) {
2020-04-11 10:37:54 +01:00
o.Prefix = p
2019-05-31 00:43:23 +01:00
}
}
2020-04-11 10:37:54 +01:00
// LockTTL sets the lock ttl
func LockTTL(t time.Duration) LockOption {
return func(o *LockOptions) {
o.TTL = t
2019-05-31 00:43:23 +01:00
}
}
2020-04-11 10:37:54 +01:00
// LockWait sets the wait time
func LockWait(t time.Duration) LockOption {
return func(o *LockOptions) {
o.Wait = t
2019-05-31 00:43:23 +01:00
}
}