mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-18 08:26:38 +02:00
1db36357d5
* feat(logger): add logger option to all components * fix: refactor api/rpc.go * fix: refactor api/stream.go * fix: api/options.go comment * fix(logger): do not use logger.Helper internally * fix(logger): fix comments * fix(logger): use level.Enabled method * fix: rename mlogger to log * fix: run go fmt * fix: log level * fix: factories Co-authored-by: Mohamed MHAMDI <mmhamdi@hubside.com> Co-authored-by: Davincible <david.brouwer.99@gmail.com>
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
// Package sync is an interface for distributed synchronization
|
|
package sync
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"errors"
|
|
"time"
|
|
|
|
"go-micro.dev/v4/logger"
|
|
)
|
|
|
|
var (
|
|
ErrLockTimeout = errors.New("lock timeout")
|
|
)
|
|
|
|
// Sync is an interface for distributed synchronization
|
|
type Sync interface {
|
|
// Initialise 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 {
|
|
Nodes []string
|
|
Prefix string
|
|
TLSConfig *tls.Config
|
|
Context context.Context
|
|
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)
|