Documentation
¶
Overview ¶
Package sets3lock provides a distributed lock mechanism using Amazon S3.
Index ¶
- func Recover(e any) error
- func WithAPIClient(client APIClient) func(*Options)
- func WithContext(ctx context.Context) func(*Options)
- func WithDelay(delay bool) func(*Options)
- func WithExpireGracePeriod(d time.Duration) func(*Options)
- func WithNoPanic() func(*Options)
- type APIClient
- type Locker
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAPIClient ¶
WithAPIClient allows you to specify a custom S3 client for the locker.
func WithContext ¶
WithContext allows you to specify a context for the locker. The context will be used for all operations of the locker.
func WithDelay ¶
WithDelay will delay the acquisition of the lock if it fails to acquire the lock. This is similar to the N option of setlock. The default is delay enabled (true). Specify false if you want to exit immediately if Lock acquisition fails.
func WithExpireGracePeriod ¶
WithExpireGracePeriod specifies the grace period after the lease expires during which the lock can still be reclaimed.
If the grace period is greater than zero, the lock may be forcibly reacquired once both the lease has expired and the specified grace period has elapsed.
If the grace period is zero or negative, automatic reclamation is disabled; expired locks will remain until removed by S3's TTL mechanism.
func WithNoPanic ¶
func WithNoPanic() func(*Options)
WithNoPanic changes the behavior so that it does not panic if an error occurs in the Locker.Lock() and Locker.Unlock() functions. Check the Locker.LastErr() function to see if an error has occurred when WithNoPanic is specified.
Types ¶
type APIClient ¶
type APIClient interface {
HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
}
APIClient is an interface for the S3 client used by Locker.
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker provides a Lock mechanism using Amazon S3.
func (*Locker) ClearLastErr ¶
func (l *Locker) ClearLastErr()
func (*Locker) LockWithErr ¶
LockWithErr try get lock. The return value of bool indicates whether the lock has been released. If true, it is lock granted.