mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
remove sync package
This commit is contained in:
parent
66b3fd8893
commit
7c3f272001
@ -1,58 +0,0 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"go-micro.dev/v5/logger"
|
||||
)
|
||||
|
||||
// Nodes sets the addresses to use.
|
||||
func Nodes(a ...string) Option {
|
||||
return func(o *Options) {
|
||||
o.Nodes = a
|
||||
}
|
||||
}
|
||||
|
||||
// Prefix sets a prefix to any lock ids used.
|
||||
func Prefix(p string) Option {
|
||||
return func(o *Options) {
|
||||
o.Prefix = p
|
||||
}
|
||||
}
|
||||
|
||||
// LockTTL sets the lock ttl.
|
||||
func LockTTL(t time.Duration) LockOption {
|
||||
return func(o *LockOptions) {
|
||||
o.TTL = t
|
||||
}
|
||||
}
|
||||
|
||||
// LockWait sets the wait time.
|
||||
func LockWait(t time.Duration) LockOption {
|
||||
return func(o *LockOptions) {
|
||||
o.Wait = t
|
||||
}
|
||||
}
|
||||
|
||||
// WithTLS sets the TLS config.
|
||||
func WithTLS(t *tls.Config) Option {
|
||||
return func(o *Options) {
|
||||
o.TLSConfig = t
|
||||
}
|
||||
}
|
||||
|
||||
// WithContext sets the syncs context, for any extra configuration.
|
||||
func WithContext(c context.Context) Option {
|
||||
return func(o *Options) {
|
||||
o.Context = c
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogger sets the underline logger.
|
||||
func WithLogger(l logger.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = l
|
||||
}
|
||||
}
|
60
sync/sync.go
60
sync/sync.go
@ -1,60 +0,0 @@
|
||||
// Package sync is an interface for distributed synchronization
|
||||
package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go-micro.dev/v5/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrLockTimeout = errors.New("lock timeout")
|
||||
)
|
||||
|
||||
// Sync is an interface for distributed synchronization.
|
||||
type Sync interface {
|
||||
// Initialize options
|
||||
Init(...Option) error
|
||||
// Return the options
|
||||
Options() Options
|
||||
// Elect a leader
|
||||
Leader(id string, opts ...LeaderOption) (Leader, error)
|
||||
// Lock acquires a lock
|
||||
Lock(id string, opts ...LockOption) error
|
||||
// Unlock releases a lock
|
||||
Unlock(id string) error
|
||||
// Sync implementation
|
||||
String() string
|
||||
}
|
||||
|
||||
// Leader provides leadership election.
|
||||
type Leader interface {
|
||||
// resign leadership
|
||||
Resign() error
|
||||
// status returns when leadership is lost
|
||||
Status() chan bool
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
Context context.Context
|
||||
Logger logger.Logger
|
||||
TLSConfig *tls.Config
|
||||
Prefix string
|
||||
Nodes []string
|
||||
}
|
||||
|
||||
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)
|
Loading…
Reference in New Issue
Block a user