2019-05-31 00:43:23 +01:00
|
|
|
// Package lock provides distributed locking
|
|
|
|
package lock
|
|
|
|
|
|
|
|
import (
|
2019-10-14 15:17:25 +01:00
|
|
|
"errors"
|
2019-05-31 00:43:23 +01:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-10-14 15:17:25 +01:00
|
|
|
var (
|
|
|
|
ErrLockTimeout = errors.New("lock timeout")
|
|
|
|
)
|
|
|
|
|
2019-05-31 00:43:23 +01:00
|
|
|
// Lock is a distributed locking interface
|
|
|
|
type Lock interface {
|
|
|
|
// Acquire a lock with given id
|
|
|
|
Acquire(id string, opts ...AcquireOption) error
|
|
|
|
// Release the lock with given id
|
|
|
|
Release(id string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
Nodes []string
|
|
|
|
Prefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
type AcquireOptions struct {
|
|
|
|
TTL time.Duration
|
|
|
|
Wait time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(o *Options)
|
|
|
|
type AcquireOption func(o *AcquireOptions)
|