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 NewUserConfig ¶ added in v0.2.0
func NewUserState ¶ added in v0.2.0
func (*Persister) Get ¶
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 ¶
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 ¶
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.