gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/sync/lock/lock.go (about)

     1  // Package lock provides distributed locking
     2  package lock
     3  
     4  import (
     5  	"errors"
     6  	"time"
     7  )
     8  
     9  var (
    10  	ErrLockTimeout = errors.New("lock timeout")
    11  )
    12  
    13  // Lock is a distributed locking interface
    14  type Lock interface {
    15  	// Acquire a lock with given id
    16  	Acquire(id string, opts ...AcquireOption) error
    17  	// Release the lock with given id
    18  	Release(id string) error
    19  }
    20  
    21  type Options struct {
    22  	Nodes  []string
    23  	Prefix string
    24  }
    25  
    26  type AcquireOptions struct {
    27  	TTL  time.Duration
    28  	Wait time.Duration
    29  }
    30  
    31  type Option func(o *Options)
    32  type AcquireOption func(o *AcquireOptions)