Documentation
¶
Overview ¶
Package setddblock provides a distributed lock mechanism using DynamoDB.
Index ¶
- Variables
- func Recover(e interface{}) error
- func WithContext(ctx context.Context) func(opts *Options)
- func WithDelay(delay bool) func(opts *Options)
- func WithEndpoint(endpoint string) func(opts *Options)
- func WithExpireGracePeriod(d time.Duration) func(opts *Options)
- func WithLeaseDuration(d time.Duration) func(opts *Options)
- func WithLogger(logger *slog.Logger) func(opts *Options)
- func WithNoPanic() func(opts *Options)
- func WithRegion(region string) func(opts *Options)
- type DynamoDBLocker
- type Options
Constants ¶
This section is empty.
Variables ¶
var (
DefaultLeaseDuration = 10 * time.Second
)
Default values
Functions ¶
func WithContext ¶ added in v0.1.0
WithContext specifies the Context used by Lock() and Unlock().
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 WithEndpoint ¶
WithEndpoint is an endpoint specification option for Local development. Please enter the URL of DynamoDB Local etc.
func WithExpireGracePeriod ¶ added in v0.6.0
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 DynamoDB's TTL mechanism.
func WithLeaseDuration ¶
WithLeaseDuration affects the heartbeat interval and TTL after Lock acquisition. The default is 10 seconds
func WithLogger ¶
WithLogger is a setting to enable the log output of DynamoDB Locker. By default, Logger that does not output anywhere is specified.
func WithNoPanic ¶
func WithNoPanic() func(opts *Options)
WithNoPanic changes the behavior so that it does not panic if an error occurs in the Lock () and Unlock () functions. Check the LastErr () function to see if an error has occurred when WithNoPanic is specified.
func WithRegion ¶
WithRegion specifies the AWS Region. Default AWS_DEFAULT_REGION env
Types ¶
type DynamoDBLocker ¶
type DynamoDBLocker struct {
// contains filtered or unexported fields
}
DynamoDBLocker implements the sync.Locker interface and provides a Lock mechanism using DynamoDB.
func New ¶
func New(urlStr string, optFns ...func(*Options)) (*DynamoDBLocker, error)
New returns *DynamoDBLocker
func (*DynamoDBLocker) ClearLastErr ¶ added in v0.3.0
func (l *DynamoDBLocker) ClearLastErr()
func (*DynamoDBLocker) LastErr ¶ added in v0.3.0
func (l *DynamoDBLocker) LastErr() error
func (*DynamoDBLocker) LockWithErr ¶
func (l *DynamoDBLocker) LockWithErr(ctx context.Context) (bool, error)
LockWithErr try get lock. The return value of bool indicates whether Lock has been released. If true, it is Lock Granted.
func (*DynamoDBLocker) UnlockWithErr ¶
func (l *DynamoDBLocker) UnlockWithErr(ctx context.Context) error
UnlockWithErr unlocks. Delete DynamoDB items
type Options ¶
type Options struct {
NoPanic bool
Logger *slog.Logger
Delay bool
Endpoint string
Region string
LeaseDuration time.Duration
ExpireGracePeriod time.Duration
// contains filtered or unexported fields
}
Options are for changing the behavior of DynamoDB Locker and are changed by the function passed to the New () function. See the WithXXX options for more information.