Documentation
¶
Index ¶
- Constants
- Variables
- func Delete(appID, keypath string) error
- func Exists(appID, keypath string) (bool, error)
- func Get(appID, keypath string) (any, error)
- func GetBool(appID, keypath string) (bool, error)
- func GetData(appID, keypath string) ([]byte, error)
- func GetDate(appID, keypath string) (time.Time, error)
- func GetFloat(appID, keypath string) (float64, error)
- func GetInt(appID, keypath string) (int64, error)
- func GetKeys(appID string) ([]string, error)
- func GetMap(appID, keypath string) (map[string]any, error)
- func GetSlice(appID, keypath string) ([]any, error)
- func GetStr(appID, keypath string) (string, error)
- func Set(appID, keypath string, value any) error
- type InternalErr
- type KeyNotFoundErr
- func (e *KeyNotFoundErr) Error() string
- func (e *KeyNotFoundErr) Is(target error) bool
- func (e *KeyNotFoundErr) Unwrap() error
- func (e *KeyNotFoundErr) WithMsg(msg string) *KeyNotFoundErr
- func (e *KeyNotFoundErr) WithMsgF(format string, a ...any) *KeyNotFoundErr
- func (e *KeyNotFoundErr) Wrap(err error) *KeyNotFoundErr
- type KeyPathErr
- type TypeMismatchErr
Constants ¶
const ( // ArrayAppendOp is a special operator used to indicate an append operation. // When used in a keypath (e.g., "array-test/items/~]"), it signals that a // new element should be appended to end of the array. ArrayAppendOp = "~]" // ArrayPrependOp is a special operator used to indicate a prepend operation. // When used in a keypath (e.g., "array-test/items/~["), it signals that a // new element should be prepended to the beginning of the array. ArrayPrependOp = "~[" )
Variables ¶
var ( // ErrKeyNotFound is returned when a requested key does not exist ErrKeyNotFound = errors.New("key not found") // ErrInvalidKeyPath is returned when a key path is malformed ErrInvalidKeyPath = errors.New("invalid key path") // ErrTypeMismatch is returned when a value is not of the expected type ErrTypeMismatch = errors.New("type mismatch") // ErrInternal is returned when an internal error occurs ErrInternal = errors.New("internal error") )
Sentinel errors for common failures
Functions ¶
func Delete ¶
Delete removes a preference value at the given keypath and application ID. If the keypath is a simple name, it deletes the entire key. If the keypath is a JSON Pointer path, it deletes the value at the specified path.
Example usage:
// Delete a simple value
err := Delete("com.example.app", "username")
// Delete a nested value
err := Delete("com.example.app", "config/server/port")
Returns an error if the keypath is invalid or the value cannot be deleted.
func Exists ¶
Exists checks if a preference key exists for the given application ID.
The keypath can be a simple name or include a JSON Pointer path (e.g., "config/server/port") to access nested values within the preference.
Example usage:
// Check if a simple key exists
exists, err := Exists("com.example.app", "username")
// Check if a nested value exists
exists, err := Exists("com.example.app", "config/server/port")
Returns true if the key exists, false otherwise.
func Get ¶
Get retrieves a preference value for the given key and application ID.
The keypath can be a simple name or include a JSON Pointer path (e.g., "config/server/port") to access nested values within the preference.
Example usage:
// Get a simple value
value, err := Get("com.example.app", "username")
// Get a nested value
value, err := Get("com.example.app", "config/server/port")
Returns the value at the specified path or an error if not found.
func GetBool ¶
GetBool retrieves a boolean preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not a boolean.
func GetData ¶ added in v0.2.0
GetData retrieves a []byte preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not a []byte.
func GetDate ¶ added in v0.2.0
GetDate retrieves a time.Time preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not a time.Time.
func GetFloat ¶
GetFloat retrieves a float preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not a float.
func GetInt ¶
GetInt retrieves an integer preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not an integer.
func GetKeys ¶ added in v0.2.0
GetKeys retrieves all keys for the given appID. Returns an error if the appID is not found.
func GetMap ¶ added in v0.2.0
GetMap retrieves a map[string]any preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not a map[string]any.
func GetSlice ¶ added in v0.2.0
GetSlice retrieves a []any preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not a []any.
func GetStr ¶
GetStr retrieves a string preference value for the given key and application ID. Returns an error if the key doesn't exist or if the value is not a string.
func Set ¶
Set writes a preference value for the given key and application ID.
The keypath can be a simple name or include a JSON Pointer path (e.g., "config/server/port") to access nested values within the preference.
Example usage:
// Set a simple value
err := Set("com.example.app", "username", "John Doe")
// Set a nested value
err := Set("com.example.app", "config/server/port", 8080)
Types ¶
type InternalErr ¶ added in v0.3.0
InternalErr represents an error that is internal to the library
func NewInternalError ¶ added in v0.3.0
func NewInternalError() *InternalErr
NewInternalError creates a new InternalErr
func (*InternalErr) Error ¶ added in v0.3.0
func (e *InternalErr) Error() string
Error returns the error message
func (*InternalErr) Is ¶ added in v0.3.0
func (e *InternalErr) Is(target error) bool
Is implements support for errors.Is
func (*InternalErr) Unwrap ¶ added in v0.3.0
func (e *InternalErr) Unwrap() error
Unwrap returns the underlying error
func (*InternalErr) WithMsg ¶ added in v0.3.0
func (e *InternalErr) WithMsg(msg string) *InternalErr
WithMsg adds a custom message to the error
func (*InternalErr) WithMsgF ¶ added in v0.3.0
func (e *InternalErr) WithMsgF(format string, a ...any) *InternalErr
WithMsgF adds a formatted custom message to the error
func (*InternalErr) Wrap ¶ added in v0.3.0
func (e *InternalErr) Wrap(err error) *InternalErr
Wrap wraps an error with the InternalErr
type KeyNotFoundErr ¶ added in v0.3.0
KeyNotFoundErr represents an error when a preference key is not found
func NewKeyNotFoundError ¶ added in v0.3.0
func NewKeyNotFoundError(appID, key string) *KeyNotFoundErr
NewKeyNotFoundError creates a new KeyNotFoundErr
func (*KeyNotFoundErr) Error ¶ added in v0.3.0
func (e *KeyNotFoundErr) Error() string
Error returns the error message
func (*KeyNotFoundErr) Is ¶ added in v0.3.0
func (e *KeyNotFoundErr) Is(target error) bool
Is implements support for errors.Is
func (*KeyNotFoundErr) Unwrap ¶ added in v0.3.0
func (e *KeyNotFoundErr) Unwrap() error
Unwrap returns the underlying error
func (*KeyNotFoundErr) WithMsg ¶ added in v0.3.0
func (e *KeyNotFoundErr) WithMsg(msg string) *KeyNotFoundErr
WithMsg adds a custom message to the error
func (*KeyNotFoundErr) WithMsgF ¶ added in v0.3.0
func (e *KeyNotFoundErr) WithMsgF(format string, a ...any) *KeyNotFoundErr
WithMsgF adds a formatted custom message to the error
func (*KeyNotFoundErr) Wrap ¶ added in v0.3.0
func (e *KeyNotFoundErr) Wrap(err error) *KeyNotFoundErr
Wrap wraps an error with the KeyNotFoundErr
type KeyPathErr ¶ added in v0.3.0
KeyPathErr represents an error with a key path
func NewKeyPathError ¶ added in v0.3.0
func NewKeyPathError() *KeyPathErr
NewKeyPathError creates a new KeyPathErr
func (*KeyPathErr) Error ¶ added in v0.3.0
func (e *KeyPathErr) Error() string
Error returns the error message
func (*KeyPathErr) Is ¶ added in v0.3.0
func (e *KeyPathErr) Is(target error) bool
Is implements support for errors.Is
func (*KeyPathErr) Unwrap ¶ added in v0.3.0
func (e *KeyPathErr) Unwrap() error
Unwrap returns the underlying error
func (*KeyPathErr) WithMsg ¶ added in v0.3.0
func (e *KeyPathErr) WithMsg(msg string) *KeyPathErr
WithMsg adds a custom message to the error
func (*KeyPathErr) WithMsgF ¶ added in v0.3.0
func (e *KeyPathErr) WithMsgF(format string, a ...any) *KeyPathErr
WithMsgF adds a formatted custom message to the error
func (*KeyPathErr) Wrap ¶ added in v0.3.0
func (e *KeyPathErr) Wrap(err error) *KeyPathErr
Wrap wraps an error with the KeyPathErr
type TypeMismatchErr ¶ added in v0.3.0
TypeMismatchErr represents a type mismatch error
func NewTypeMismatchError ¶ added in v0.3.0
func NewTypeMismatchError(expected, actual any) *TypeMismatchErr
NewTypeMismatchError creates a new TypeMismatchErr
func (*TypeMismatchErr) Error ¶ added in v0.3.0
func (e *TypeMismatchErr) Error() string
Error returns the error message
func (*TypeMismatchErr) Is ¶ added in v0.3.0
func (e *TypeMismatchErr) Is(target error) bool
Is implements support for errors.Is
func (*TypeMismatchErr) Unwrap ¶ added in v0.3.0
func (e *TypeMismatchErr) Unwrap() error
Unwrap returns the underlying error
func (*TypeMismatchErr) WithKey ¶ added in v0.3.0
func (e *TypeMismatchErr) WithKey(appID, key string) *TypeMismatchErr
WithKey adds an appID and key to the error
func (*TypeMismatchErr) Wrap ¶ added in v0.3.0
func (e *TypeMismatchErr) Wrap(err error) *TypeMismatchErr
Wrap wraps an error with the TypeMismatchErr