lockers

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("canceled")
View Source
var LockerTypes = []string{
	"consul",
	"k8s",
	"redis",
}
View Source
var Lockers = map[string]Initializer{}

Functions

func DecodeConfig

func DecodeConfig(src, dst interface{}) error

func Register

func Register(name string, initFn Initializer)

Types

type Initializer

type Initializer func() Locker

type Locker

type Locker interface {
	// Init initialises the locker data, with the given configuration read from flags/files.
	Init(context.Context, map[string]interface{}, ...Option) error
	// Stop is called when the locker instance is called. It should unlock all acquired locks.
	Stop() error
	SetLogger(*log.Logger)

	// Lock acquires a lock on given key.
	Lock(context.Context, string, []byte) (bool, error)
	// KeepLock maintains the lock on the target.
	KeepLock(context.Context, string) (chan struct{}, chan error)
	// IsLocked replys if the target given as string is currently locked or not.
	IsLocked(context.Context, string) (bool, error)
	// Unlock unlocks the target log.
	Unlock(context.Context, string) error

	// Register registers this instance in the registry. It must also maintain the registration (called in a goroutine from the main). ServiceRegistration.ID contains the ID of the service to register.
	Register(context.Context, *ServiceRegistration) error
	// Deregister removes this instance from the registry. This looks like it's not called.
	Deregister(string) error

	// GetServices must return the gnmic instances.
	GetServices(ctx context.Context, serviceName string, tags []string) ([]*Service, error)
	// WatchServices must push all existing discovered gnmic instances
	// into the provided channel.
	WatchServices(ctx context.Context, serviceName string, tags []string, ch chan<- []*Service, dur time.Duration) error

	// List returns all locks that start with prefix string,
	// indexed by the lock name. Could be target locks or leader lock. It must return a map of matching keys to instance name.
	List(ctx context.Context, prefix string) (map[string]string, error)
}

type Option

type Option func(Locker)

func WithLogger

func WithLogger(logger *log.Logger) Option

type Service

type Service struct {
	ID      string
	Address string
	Tags    []string
}

type ServiceRegistration

type ServiceRegistration struct {
	ID      string
	Name    string
	Address string
	Port    int
	Tags    []string
	TTL     time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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