appsettings

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2017 License: MIT Imports: 6 Imported by: 1

README

AppSettings

GoDoc

A hierarchical key value store for persisting simple runtime options in Go applications.

Example

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

Installation

go get -u -v github.com/donatj/appsettings

Migration from v0.0.1

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

Documentation can be found a godoc:

https://godoc.org/github.com/donatj/appsettings

Documentation

Overview

Package appsettings provides simple key/value store functionality

Index

Constants

This section is empty.

Variables

View Source
var ErrUndefinedKey = errors.New("undefined key")

ErrUndefinedKey is returned when the key requested from get is undefined.

Functions

This section is empty.

Types

type AppSettings

type AppSettings struct {
	// contains filtered or unexported fields
}

AppSettings is the root most DataTree

func NewAppSettings

func NewAppSettings(dbFilename string) (*AppSettings, error)

NewAppSettings gets a new AppSettings struct

func (AppSettings) Delete added in v0.1.0

func (a AppSettings) Delete(key string)

func (AppSettings) DeleteTree added in v0.2.0

func (a AppSettings) DeleteTree(key string)

func (AppSettings) GetInt added in v0.1.0

func (a AppSettings) GetInt(key string) (int, error)

func (AppSettings) GetInt64 added in v0.1.0

func (a AppSettings) GetInt64(key string) (int64, error)

func (AppSettings) GetLeaves added in v0.1.0

func (a AppSettings) GetLeaves() map[string]string

func (AppSettings) GetString added in v0.1.0

func (a AppSettings) GetString(key string) (string, error)

func (AppSettings) GetTree

func (a AppSettings) GetTree(key string) DataTree

GetTree fetches a tree for app setting storage

func (AppSettings) GetTrees added in v0.2.0

func (a AppSettings) GetTrees() map[string]*tree

func (*AppSettings) Persist

func (a *AppSettings) Persist() error

Persist causes the current state of the app settings to be persisted.

func (AppSettings) SetInt added in v0.1.0

func (a AppSettings) SetInt(key string, val int)

func (AppSettings) SetInt64 added in v0.1.0

func (a AppSettings) SetInt64(key string, val int64)

func (AppSettings) SetString added in v0.1.0

func (a AppSettings) SetString(key string, val string)

type DataTree

type DataTree interface {
	GetString(key string) (string, error)
	SetString(key string, val string)
	GetInt(key string) (int, error)
	SetInt(key string, val int)
	GetInt64(key string) (int64, error)
	SetInt64(key string, val int64)
	Delete(key string)
	DeleteTree(key string)
	GetTree(key string) DataTree

	GetTrees() map[string]*tree
	GetLeaves() map[string]string
}

DataTree is the host of key and branches of values

Jump to

Keyboard shortcuts

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