local

package
v0.0.0-...-43bd847 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package local contains functions and interfaces that are shared between functions and resources. It's similar to the "world" functionality, except that it only involves local operations that stay within a single machine or local mgmt instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Prefix string
	Debug  bool
	Logf   func(format string, v ...interface{})

	// Each piece of the API can take a handle here.
	*Value // TODO: Rename to ValueImpl?

	// VarDirImpl is the implementation for the VarDir API's. The API's are
	// the collection of public methods that exist on this struct.
	*VarDirImpl

	// PoolImpl is the implementation for the Pool API's. The API's are the
	// collection of public methods that exist on this struct.
	*PoolImpl
}

API implements the base handle for all the methods in this package. If we were going to have more than one implementation for all of these, then this would be an interface instead, and different packages would implement it. Since this is not the expectation for the local API, it's all self-contained.

func (*API) Init

func (obj *API) Init() *API

Init initializes the API before first use. It returns itself so it can be chained for API aesthetical purposes.

type PoolConfig

type PoolConfig struct {
	// Expiry specifies that we expire old values that have not been read
	// for this many seconds. Zero disables this and they never expire.
	Expiry int64 // TODO: or time.Time ?

	// Random lets you allocate a random integer instead of sequential ones.
	Random bool

	// Max specifies the maximum integer to allocate.
	Max int
}

PoolConfig configures how the Pool operates. XXX: These are not implemented yet.

type PoolImpl

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

PoolImpl is the implementation for the Pool API's. The API's are the collection of public methods that exist on this struct.

func (*PoolImpl) Init

func (obj *PoolImpl) Init(init *PoolInit)

Init runs some initialization code for the Pool API.

func (*PoolImpl) Pool

func (obj *PoolImpl) Pool(ctx context.Context, namespace, uid string, config *PoolConfig) (int, error)

Pool returns a unique integer from a pool of numbers. Within a given namespace, it returns the same integer for a given name. It is a simple mechanism to allocate numbers to different inputs when we don't have a hashing alternative. It does not allocate zero.

type PoolInit

type PoolInit struct {
	Prefix string
	Debug  bool
	Logf   func(format string, v ...interface{})
}

PoolInit are the init values that the Pool API needs to work correctly.

type Value

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

Value is the API for getting, setting, and watching local values.

func (*Value) Init

func (obj *Value) Init(init *ValueInit)

Init runs some initialization code for the Value API.

func (*Value) ValueGet

func (obj *Value) ValueGet(ctx context.Context, key string) (interface{}, error)

ValueGet pulls a value out of a local in-memory, key-value store that is backed by on-disk storage. While each value is intended to have an underlying type, we use the `any` or empty `interface{}` value to represent each value instead of a `types.Value` because it's more generic, and not limited to being used with the language type system. If the value doesn't exist, we return a nil value and no error.

func (*Value) ValueSet

func (obj *Value) ValueSet(ctx context.Context, key string, value interface{}) error

ValueSet sets a value to our in-memory, key-value store that is backed by on-disk storage. If you provide a nil value, this is the equivalent of removing or deleting the value.

func (*Value) ValueWatch

func (obj *Value) ValueWatch(ctx context.Context, key string) (chan struct{}, error)

ValueWatch watches a value from our in-memory, key-value store that is backed by on-disk storage. Conveniently, it never has to watch the on-disk storage, because after the initial startup which always sends a single startup event, it suffices to watch the in-memory store for events!

type ValueInit

type ValueInit struct {
	Prefix string
	Debug  bool
	Logf   func(format string, v ...interface{})
}

ValueInit are the init values that the Value API needs to work correctly.

type VarDirImpl

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

VarDirImpl is the implementation for the VarDir API's. The API's are the collection of public methods that exist on this struct.

func (*VarDirImpl) Init

func (obj *VarDirImpl) Init(init *VarDirInit)

Init runs some initialization code for the VarDir API.

func (*VarDirImpl) VarDir

func (obj *VarDirImpl) VarDir(ctx context.Context, reldir string) (string, error)

VarDir returns a directory rooted at the internal prefix.

type VarDirInit

type VarDirInit struct {
	Prefix string
	Debug  bool
	Logf   func(format string, v ...interface{})
}

VarDirInit are the init values that the VarDir API needs to work correctly.

Jump to

Keyboard shortcuts

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