2019-05-31 01:43:23 +02:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
2022-08-11 07:09:25 +02:00
|
|
|
"context"
|
2022-02-24 11:07:14 +02:00
|
|
|
"crypto/tls"
|
2020-04-11 11:37:54 +02:00
|
|
|
"time"
|
2022-09-29 16:44:53 +02:00
|
|
|
|
|
|
|
"go-micro.dev/v4/logger"
|
2019-05-31 01:43:23 +02:00
|
|
|
)
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// Nodes sets the addresses to use.
|
2020-04-11 11:37:54 +02:00
|
|
|
func Nodes(a ...string) Option {
|
2019-05-31 01:43:23 +02:00
|
|
|
return func(o *Options) {
|
2020-04-11 11:37:54 +02:00
|
|
|
o.Nodes = a
|
2019-05-31 01:43:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// Prefix sets a prefix to any lock ids used.
|
2020-04-11 11:37:54 +02:00
|
|
|
func Prefix(p string) Option {
|
2019-05-31 01:43:23 +02:00
|
|
|
return func(o *Options) {
|
2020-04-11 11:37:54 +02:00
|
|
|
o.Prefix = p
|
2019-05-31 01:43:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// LockTTL sets the lock ttl.
|
2020-04-11 11:37:54 +02:00
|
|
|
func LockTTL(t time.Duration) LockOption {
|
|
|
|
return func(o *LockOptions) {
|
|
|
|
o.TTL = t
|
2019-05-31 01:43:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// LockWait sets the wait time.
|
2020-04-11 11:37:54 +02:00
|
|
|
func LockWait(t time.Duration) LockOption {
|
|
|
|
return func(o *LockOptions) {
|
|
|
|
o.Wait = t
|
2019-05-31 01:43:23 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-24 11:07:14 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// WithTLS sets the TLS config.
|
2022-02-24 11:07:14 +02:00
|
|
|
func WithTLS(t *tls.Config) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.TLSConfig = t
|
|
|
|
}
|
|
|
|
}
|
2022-08-11 07:09:25 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// WithContext sets the syncs context, for any extra configuration.
|
2022-08-11 07:09:25 +02:00
|
|
|
func WithContext(c context.Context) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Context = c
|
|
|
|
}
|
|
|
|
}
|
2022-09-29 16:44:53 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// WithLogger sets the underline logger.
|
2022-09-29 16:44:53 +02:00
|
|
|
func WithLogger(l logger.Logger) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Logger = l
|
|
|
|
}
|
|
|
|
}
|