locker

package
v0.0.0-...-e282ec7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyLocked      = errors.New("key is locked")
	ErrLockerIsExpire = errors.New("locker is expire")
	ErrLockerNotFound = errors.New("locker does not exists")
	ErrMaxAttempts    = errors.New("maximum number of attempts reached")
)

Functions

func Lock

func Lock(ctx context.Context, key string, opts ...Option) (string, error)

func SetDefaultLocker

func SetDefaultLocker(l Locker)

func Unlock

func Unlock(ctx context.Context, key string, id string) error

Types

type Locker

type Locker interface {
	Init(config string) error
	Close() error

	Lock(ctx context.Context, key string, opts ...Option) (string, error)
	Unlock(ctx context.Context, key string, id string) error
}

type OSLocker

type OSLocker struct {
	// contains filtered or unexported fields
}

func (*OSLocker) Close

func (o *OSLocker) Close() error

func (*OSLocker) Init

func (o *OSLocker) Init(config string) error

func (*OSLocker) Lock

func (o *OSLocker) Lock(ctx context.Context, key string, opts ...Option) (string, error)

func (*OSLocker) Unlock

func (o *OSLocker) Unlock(ctx context.Context, key string, id string) error

type Option

type Option func(*Options)

func WithExpiration

func WithExpiration(d time.Duration) Option

func WithMaxAttempts

func WithMaxAttempts(count int) Option

type Options

type Options struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL