A hierarchical key value store for persisting simple runtime options in Go applications.
s := appsettings.NewAppSettings("settings.json")
t := s.GetTree("user-settings")
//set
t.SetString("pizza", "pie")
t.SetInt("how-many-pugs", 349)
//read
if v, err := t.GetInt("how-many-pugs"); err == nil {
log.Println(v)
}
if v, err = t.GetString("pizza"); err == nil {
log.Println(v)
}
s.Persist()
$ go install github.com/donatj/appsettings/cmd/appsettings@latest
The JSON format for the early Alpha changed. To migrate your existing data compatibly to the more modern format, you can use jq and execute the following command, first replacing {your-file}
with the path to your actual database file.
jq '.Tree |= with_entries(.value = {Leaves: .value} ) | . + {Branches: .Tree} | del(.Tree)' < {your-file} > tmp && mv tmp {your-fie}
Documentation can be found a godoc: