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
}
Persister represents a simple key-value storage system using the Java Persister file format. Deviations from the standard Properties specification:
- Comments re not supported and will result in an error if present. - Blank lines are not allowed and will also result in an error. - Every line must be a valid `key=value` pair; otherwise, ignored.
Supported features ¶
- Keys and values are trimmed of leading and trailing whitespace. - Special characters are escaped and unescaped automatically. - The file format is compatible with most Persister parsers.
Usage ¶
storage := &inprops.Persister{File: "data.properties"} 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.