inyaml

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Persister

type Persister struct {
	File string // consider someplace in futil.UserStateDir()
}

Persister represents a key-value storage system using the YAML format.

Features:

- Values are stored as strings and loaded directly into a flat key-value map. - The file format is compatible with standard Persister parsers.

Usage

	     storage := &inyaml.Persister{File: "data.yaml"}
    	 storage.Setup()
	     storage.Set("key", "value")
	     value := storage.Get("key")

func NewUserCache added in v0.2.0

func NewUserCache(name, file string) *Persister

func NewUserConfig added in v0.2.0

func NewUserConfig(name, file string) *Persister

func NewUserState added in v0.2.0

func NewUserState(name, file string) *Persister

func (*Persister) Get

func (p *Persister) Get(key string) string

Get retrieves the value associated with the given key from the persisted data. The method loads the data from the persistence file in a way that is both safe for concurrency and locked against use by other programs using the lockedfile package (like go binary itself does). If the key is not present in the data, a nil value will be returned.

func (*Persister) Set

func (p *Persister) Set(key, value string)

Set stores a key-value pair in the persisted data. The method loads the existing data from the persistence file, updates the data with the new key-value pair, and saves it back to the file.

func (*Persister) Setup

func (p *Persister) Setup() error

Setup ensures that the persistence file exists and is ready for use. It opens the file in read-only mode, creating it if it doesn't already exist, and applies secure file permissions (0600) to restrict access. The file is immediately closed after being verified or created. If the file cannot be opened or created, an error is returned.

Jump to

Keyboard shortcuts

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