gitee.com/sasukebo/go-micro/v4@v4.7.1/sync/sync.go (about) 1 // Package sync is an interface for distributed synchronization 2 package sync 3 4 import ( 5 "crypto/tls" 6 "errors" 7 "time" 8 ) 9 10 var ( 11 ErrLockTimeout = errors.New("lock timeout") 12 ) 13 14 // Sync is an interface for distributed synchronization 15 type Sync interface { 16 // Initialise options 17 Init(...Option) error 18 // Return the options 19 Options() Options 20 // Elect a leader 21 Leader(id string, opts ...LeaderOption) (Leader, error) 22 // Lock acquires a lock 23 Lock(id string, opts ...LockOption) error 24 // Unlock releases a lock 25 Unlock(id string) error 26 // Sync implementation 27 String() string 28 } 29 30 // Leader provides leadership election 31 type Leader interface { 32 // resign leadership 33 Resign() error 34 // status returns when leadership is lost 35 Status() chan bool 36 } 37 38 type Options struct { 39 Nodes []string 40 Prefix string 41 TLSConfig *tls.Config 42 } 43 44 type Option func(o *Options) 45 46 type LeaderOptions struct{} 47 48 type LeaderOption func(o *LeaderOptions) 49 50 type LockOptions struct { 51 TTL time.Duration 52 Wait time.Duration 53 } 54 55 type LockOption func(o *LockOptions)