kdb

package
v0.0.0-...-7a7dc14 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResource            = errors.New("C01100 - Resource")
	ErrOutOfMemory         = errors.New("C01110 - OutOfMemory")
	ErrInstallation        = errors.New("C01200 - Installation")
	ErrInternal            = errors.New("C01310 - Internal")
	ErrInterface           = errors.New("C01320 - Interface")
	ErrPluginMisbehavior   = errors.New("C01330 - PluginMisbehavior")
	ErrConflictingState    = errors.New("C02000 - ConflictingState")
	ErrValidationSyntactic = errors.New("C03100 - ValidationSyntactic")
	ErrValidationSemantic  = errors.New("C03200 - ValidationSemantic")
)

error codes taken from libelektra/src/error/specification

Functions

func CommonKeyName

func CommonKeyName(key1, key2 Key) string

CommonKeyName returns the common path of two Keys.

Types

type CKey

type CKey struct {
	Ptr *C.struct__Key
}

func (*CKey) BaseName

func (k *CKey) BaseName() string

BaseName returns the basename of the Key. Some examples: - BaseName of system:/some/keyname is keyname - BaseName of "user:/tmp/some key" is "some key"

func (*CKey) Bytes

func (k *CKey) Bytes() []byte

Bytes returns the value of the Key as a byte slice.

func (*CKey) Close

func (k *CKey) Close()

Close free's the underlying key's memory. This needs to be done for Keys that are created by NewKey() or Key.Duplicate().

func (*CKey) Compare

func (k *CKey) Compare(other Key) int

Compare the name of two keys. It returns 0 if the keys are equal, < 0 if this key is less than `other` Key and > 0 if this key is greater than `other` Key. This function defines the sorting order of a KeySet.

func (*CKey) Duplicate

func (k *CKey) Duplicate(flags KeyCopyFlags) Key

Duplicate duplicates a Key.

func (*CKey) IsBelow

func (k *CKey) IsBelow(other Key) bool

IsBelow checks if this key is below the `other` key.

func (*CKey) IsBelowOrSame

func (k *CKey) IsBelowOrSame(other Key) bool

IsBelowOrSame checks if this key is below or the same as the `other` key.

func (*CKey) IsDirectlyBelow

func (k *CKey) IsDirectlyBelow(other Key) bool

IsDirectlyBelow checks if this key is directly below the `other` Key.

func (*CKey) Meta

func (k *CKey) Meta(name string) string

Meta retrieves the Meta value of a Key.

func (*CKey) MetaMap

func (k *CKey) MetaMap() map[string]string

MetaMap builds a Key/Value map of all meta Keys.

func (*CKey) MetaSlice

func (k *CKey) MetaSlice() []Key

MetaSlice builds a slice of all meta Keys.

func (*CKey) Name

func (k *CKey) Name() string

Name returns the name of the Key.

func (*CKey) Namespace

func (k *CKey) Namespace() ElektraNamespace

Namespace returns the namespace of a Key.

func (*CKey) RemoveMeta

func (k *CKey) RemoveMeta(name string) error

RemoveMeta deletes a meta Key.

func (*CKey) SetBoolean

func (k *CKey) SetBoolean(value bool) error

SetBoolean sets the string of a key to a boolean where true is represented as "1" and false as "0".

func (*CKey) SetBytes

func (k *CKey) SetBytes(value []byte) error

SetBytes sets the value of a key to a byte slice.

func (*CKey) SetMeta

func (k *CKey) SetMeta(name, value string) error

SetMeta sets the meta value of a Key.

func (*CKey) SetName

func (k *CKey) SetName(name string) error

SetName sets the name of the Key.

func (*CKey) SetString

func (k *CKey) SetString(value string) error

SetString sets the string of a key.

func (*CKey) String

func (k *CKey) String() string

String returns the string value of the Key.

type CKeySet

type CKeySet struct {
	Ptr *C.struct__KeySet
}

func (*CKeySet) Append

func (ks *CKeySet) Append(other KeySet) int

Append appends all Keys from `other` to this KeySet and returns the new length of this KeySet or -1 if `other` is not a KeySet which was created by elektra/kdb.

func (*CKeySet) AppendKey

func (ks *CKeySet) AppendKey(key Key) int

AppendKey appends a Key to this KeySet and returns the new length of this KeySet or -1 if the key is not a Key created by elektra/kdb.

func (*CKeySet) Clear

func (ks *CKeySet) Clear()

Clear removes all Keys from the KeySet.

func (*CKeySet) Close

func (ks *CKeySet) Close()

Close needs to be called on a KeySet after it is not in use anymore to free the allocated memory.

func (*CKeySet) Copy

func (ks *CKeySet) Copy(keySet KeySet)

Copy copies the entire KeySet to the passed KeySet.

func (*CKeySet) Cut

func (ks *CKeySet) Cut(key Key) KeySet

Cut cuts out a new KeySet at the cutpoint key and returns it.

func (*CKeySet) Duplicate

func (ks *CKeySet) Duplicate() KeySet

Duplicate returns a new duplicated keyset.

func (*CKeySet) ForEach

func (ks *CKeySet) ForEach(iterator Iterator)

ForEach accepts an `Iterator` that loops over every Key in the KeySet.

func (*CKeySet) KeyNames

func (ks *CKeySet) KeyNames() []string

KeyNames returns a slice of the name of every Key in the KeySet.

func (*CKeySet) Len

func (ks *CKeySet) Len() int

Len returns the length of the KeySet.

func (*CKeySet) Lookup

func (ks *CKeySet) Lookup(key Key) Key

Lookup searches the KeySet for a certain Key.

func (*CKeySet) LookupByName

func (ks *CKeySet) LookupByName(name string) Key

LookupByName searches the KeySet for a Key by name.

func (*CKeySet) Pop

func (ks *CKeySet) Pop() Key

Pop removes and returns the last Element that was added to the KeySet.

func (*CKeySet) Remove

func (ks *CKeySet) Remove(key Key) Key

Remove removes a key from the KeySet and returns it if found.

func (*CKeySet) RemoveByName

func (ks *CKeySet) RemoveByName(name string) Key

RemoveByName removes a key by its name from the KeySet and returns it if found.

func (*CKeySet) ToSlice

func (ks *CKeySet) ToSlice() []Key

ToSlice returns a slice containing all Keys.

type ElektraError

type ElektraError struct {
	Err         error
	Description string
	Number      string
	Reason      string
	Ingroup     string
	Module      string
	File        string
	Line        string
}

func (*ElektraError) Error

func (e *ElektraError) Error() string

func (*ElektraError) Unwrap

func (e *ElektraError) Unwrap() error

type ElektraNamespace

type ElektraNamespace uint

type Iterator

type Iterator func(k Key, i int)

Iterator is a function that loops over Keys.

type KDB

type KDB interface {
	Open() error
	Close() error

	Get(keySet KeySet, parentKey Key) (changed bool, err error)
	Set(keySet KeySet, parentKey Key) (changed bool, err error)

	Version() (string, error)
}

KDB (key data base) access functions

func New

func New() KDB

New returns a new KDB instance.

type KdbC

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

func (*KdbC) Close

func (e *KdbC) Close() error

Close closes the kdb handle.

func (*KdbC) Get

func (e *KdbC) Get(keySet KeySet, parentKey Key) (bool, error)

Get retrieves parentKey and all Keys beneath it. Returns true if Keys have been loaded or updated and an error if something went wrong.

func (*KdbC) Open

func (e *KdbC) Open() error

Open creates a handle to the kdb library, this is mandatory to Get / Set Keys.

func (*KdbC) OpenWithContract

func (e *KdbC) OpenWithContract(contract KeySet) error

Open creates a handle to the kdb library, this is mandatory to Get / Set Keys. This function also enforces a contract.

func (*KdbC) Set

func (e *KdbC) Set(keySet KeySet, parentKey Key) (bool, error)

Set sets all Keys of a KeySet. Returns true if any of the keys have changed and an error if something happened (such as a conflict).

func (*KdbC) Version

func (e *KdbC) Version() (string, error)

Version `Get`s the current version of Elektra from the "system:/elektra/version/constants/KDB_VERSION" key in the format Major.Minor.Micro, be aware that this can lead to unexpected state-changes.

type Key

type Key interface {
	Name() string
	Namespace() ElektraNamespace
	BaseName() string

	String() string
	Bytes() []byte

	Close()

	Meta(name string) string
	MetaMap() map[string]string
	RemoveMeta(name string) error
	MetaSlice() []Key

	IsBelow(key Key) bool
	IsBelowOrSame(key Key) bool
	IsDirectlyBelow(key Key) bool
	Compare(key Key) int

	Duplicate(flags KeyCopyFlags) Key

	SetMeta(name, value string) error
	SetName(name string) error
	SetString(value string) error
	SetBytes(value []byte) error
}

Key is the wrapper around the Elektra Key.

func NewKey

func NewKey(name string, value ...interface{}) (Key, error)

NewKey creates a new `Key` with an optional value.

type KeyCopyFlags

type KeyCopyFlags uint
const (
	KEY_CP_NAME   KeyCopyFlags = C.KEY_CP_NAME
	KEY_CP_VALUE  KeyCopyFlags = C.KEY_CP_VALUE
	KEY_CP_STRING KeyCopyFlags = C.KEY_CP_STRING
	KEY_CP_META   KeyCopyFlags = C.KEY_CP_META
	KEY_CP_ALL    KeyCopyFlags = C.KEY_CP_ALL
)

type KeySet

type KeySet interface {
	Copy(keySet KeySet)
	Append(keySet KeySet) int
	AppendKey(key Key) int
	Remove(key Key) Key
	RemoveByName(name string) Key
	Duplicate() KeySet

	Pop() Key
	Len() int

	Cut(key Key) KeySet

	Close()

	ForEach(iterator Iterator)
	ToSlice() []Key
	KeyNames() []string

	Clear()

	Lookup(key Key) Key
	LookupByName(name string) Key
}

KeySet represents a collection of Keys.

func NewKeySet

func NewKeySet(keys ...Key) KeySet

NewKeySet creates a new KeySet.

Jump to

Keyboard shortcuts

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