inprops

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
}

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 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