locker

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLockTaken         = errors.New("lock already taken")
	ErrLockNotExist      = errors.New("lock does not exist")
	ErrReadLock          = errors.New("could not read lock info")
	ErrRemoveLock        = errors.New("could not remove lock")
	ErrEncodeMetadata    = errors.New("could not encode metadata")
	ErrDecodeMetadata    = errors.New("could not decode metadata")
	ErrWriteMetadata     = errors.New("could not write metadata")
	ErrReadMetadata      = errors.New("could not read metadata")
	ErrRemoveMetadata    = errors.New("could not remove metadata")
	ErrGenNumberMismatch = errors.New("generation number mismatch")
)

Functions

This section is empty.

Types

type FsLocker

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

func NewFsLocker

func NewFsLocker(rootDir string) (*FsLocker, error)

func (*FsLocker) Expired

func (fs *FsLocker) Expired(key string) (int64, bool, error)

func (*FsLocker) Lock

func (fs *FsLocker) Lock(key string, ttl time.Duration) (int64, error)

func (*FsLocker) Refresh

func (fs *FsLocker) Refresh(key string, generation int64) (int64, error)

func (*FsLocker) Release

func (fs *FsLocker) Release(key string, generation int64) error

type Locker

type Locker interface {
	// Lock accepts a lock key as well as the TTL for the lock
	// and returns the generation number if lock was acquired or
	// an error otherwise
	Lock(key string, ttl time.Duration) (int64, error)

	// Refresh accepts a lock key as well as a generation number
	// and returns a new generation number if refresh was succesfull
	// or an error otherwise
	Refresh(key string, generation int64) (int64, error)

	// Release accepts a lock key as well as a generation number and
	// returns an error if lock release fails
	Release(key string, generation int64) error

	// Check if lock is expired and returns generation number that
	// should be used for lock release if it is expired
	Expired(key string) (int64, bool, error)
}

type Metadata

type Metadata struct {
	TTL     int64 `json:"ttl"`
	Expires int64 `json:"expires"`
}

func NewMetadata

func NewMetadata(ttl time.Duration) *Metadata

func ParseMetadata

func ParseMetadata(data []byte) (*Metadata, error)

func (*Metadata) Encode

func (md *Metadata) Encode() ([]byte, error)

Jump to

Keyboard shortcuts

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