Documentation ¶
Index ¶
- Variables
- type FlagValue
- type KeyValueStore
- func (store *KeyValueStore) Close()
- func (kv KeyValueStore) Exchange(key, value string) (string, error)
- func (kv KeyValueStore) ExchangeBool(key string, val bool) (bool, error)
- func (kv KeyValueStore) Get(key string) (string, error)
- func (kv KeyValueStore) GetBoolDef(key string) bool
- func (kvs *KeyValueStore) GetFlagValue(key string, validators ...func(string) error) FlagValue
- func (kv KeyValueStore) Set(key, value string) error
- func (kv KeyValueStore) SetBool(key string, val bool) error
- func (kv KeyValueStore) Unset(key string) error
Constants ¶
This section is empty.
Variables ¶
var ErrNoRows = sql.ErrNoRows
Functions ¶
This section is empty.
Types ¶
type FlagValue ¶
type FlagValue struct {
// contains filtered or unexported fields
}
FlagValue implements the flag.Value interface. See KeyValueStore.GetFlagValue for usage.
func (FlagValue) Get ¶
func (fv FlagValue) Get() interface{}
Get the key associated with fv, as a string. If the key was not set, return "".
type KeyValueStore ¶
func OpenDB ¶
func OpenDB(db *sql.DB, driverName string) (*KeyValueStore, error)
OpenDB accepts *sql.DB and driver name to an open github.com/mattn/go-sqlite3 database. It creates the appropriate table if not present, and returns a KeyValueStore. Tables are created with the `keyvalue_` prefix; no tables starting with `keyvalue_` should be in this database if using this mode.
func OpenFile ¶
func OpenFile(name string) (*KeyValueStore, error)
OpenFile takes a filename. It will open the file as a SQLite database, creating it if it doesn't exist.
func (*KeyValueStore) Close ¶
func (store *KeyValueStore) Close()
Close cleans up the database. If KeyValueStore was created by OpenFile, the backing file is closed; otherwise, the references to the underlying database are just dropped.
func (KeyValueStore) Exchange ¶
func (kv KeyValueStore) Exchange(key, value string) (string, error)
Sets "key" to "value", returning the old value, or an empty string if there is no previous value.
func (KeyValueStore) ExchangeBool ¶
func (kv KeyValueStore) ExchangeBool(key string, val bool) (bool, error)
func (KeyValueStore) Get ¶
func (kv KeyValueStore) Get(key string) (string, error)
Get looks the value of "key" in the store. If found, it returns the value; if not found, it will return ErrNoRows.
func (KeyValueStore) GetBoolDef ¶
func (kv KeyValueStore) GetBoolDef(key string) bool
GetBoolDef looks for the value of "key" in the store. If found it returns the value; on any error it returns "false".
func (*KeyValueStore) GetFlagValue ¶
func (kvs *KeyValueStore) GetFlagValue(key string, validators ...func(string) error) FlagValue
GetFlagValue returns a structure of type FlagValue, which can be passed in to flag.Var*() functions. When the flag is set, the key will be set to the value of the flag.
For example:
flag.Var(kv.GetFlagValue("ServerAddress"), "address", "Address to serve http from")
For now, keyvalue databases must be opened before flags are read, with a fixed filename. Allowing the filename to be one of the flags is a future feature.
func (KeyValueStore) Set ¶
func (kv KeyValueStore) Set(key, value string) error
Set "key" to "value" in the store.
func (KeyValueStore) SetBool ¶
func (kv KeyValueStore) SetBool(key string, val bool) error
SetBool sets "key" to a stringified boolean of "val".
func (KeyValueStore) Unset ¶
func (kv KeyValueStore) Unset(key string) error
Delete a key from the store. Future Get() calls will return ErrNoRows.