Documentation ¶
Overview ¶
Package data contains generalized data management tactics & strategies. Currently this package provides four interrelated structures:
- Trie A trie constructed from https://github.com/tchap/go-patricia with a variety of changes and additions. No optimisation is promised.
- Item A general interface for managing a key and a value. A key is a string and a value may be anything. The package provides for a variety of common types, providing example for any type you might have need to construct.
- Vector A sync.Mutex bound struct wrapping a Trie holding any number of package level Item.
- Store An interface for managing the storage of Vector in and out of any variety of formats. Package provides common stores to take a Vector to stdout(out only), json, formatted json, and yaml. An example use might take a Vector to json, sent elsewhere and modified, returned and used as a Vector, viewed in a terminal, saved as yaml and returned Vector, etc et al. Store is meant as a rough data interchange manager mediating Vector to any format you might need or want.
Index ¶
- Constants
- Variables
- func Exist(path string)
- func Open(path string) (*os.File, error)
- func SetStore(fs ...*StoreMaker)
- type BoolItem
- type Cloner
- type Float64Item
- type InFunc
- type Int64Item
- type IntItem
- type Item
- type JsonTransmitter
- type Keyer
- type Mtem
- type Option
- type OutFunc
- type Prefix
- type ReadFunc
- type Retriever
- type Store
- type StoreFn
- type StoreMaker
- type Stores
- type StringItem
- type StringsItem
- type Transmitter
- type Trie
- func (t *Trie) Delete(p Prefix) bool
- func (t *Trie) DeleteSubtree(p Prefix) bool
- func (t *Trie) Item() Item
- func (t *Trie) Match(p Prefix) bool
- func (t *Trie) MatchSubtree(p Prefix) bool
- func (t *Trie) Tagged() string
- func (t *Trie) Visit(v VisitorFunc) error
- func (t *Trie) VisitPrefixes(p Prefix, v VisitorFunc) error
- func (t *Trie) VisitSubtree(p Prefix, v VisitorFunc) error
- type Uint64Item
- type UintItem
- type Valuer
- type Vector
- func (v *Vector) Blacklist(keys ...string)
- func (v *Vector) Clear()
- func (v *Vector) Clone(except ...string) *Vector
- func (v *Vector) CloneAs(tag string, except ...string) *Vector
- func (v *Vector) Get(k string) Item
- func (v *Vector) Keys() []string
- func (v *Vector) List(except ...string) []Item
- func (v *Vector) MarshalJSON() ([]byte, error)
- func (v *Vector) MarshalYAML() (interface{}, error)
- func (v *Vector) Match(k string) []Item
- func (v *Vector) Merge(vs ...*Vector)
- func (v *Vector) Reset()
- func (v *Vector) Retag(t string)
- func (v *Vector) Set(i ...Item)
- func (v *Vector) SetBool(k string, vi bool)
- func (v *Vector) SetFloat64(k string, vi float64)
- func (v *Vector) SetInt(k string, vi int)
- func (v *Vector) SetInt64(k string, vi int64)
- func (v *Vector) SetString(k, vi string)
- func (v *Vector) SetStrings(k string, vi ...string)
- func (v *Vector) SetUint(k string, vi uint)
- func (v *Vector) SetUint64(k string, vi uint64)
- func (v *Vector) SetVector(k string, vi *Vector)
- func (v *Vector) Tag() string
- func (v *Vector) TemplateData() map[string]interface{}
- func (v *Vector) ToBool(k string) bool
- func (v *Vector) ToFloat64(k string) float64
- func (v *Vector) ToInt(k string) int
- func (v *Vector) ToInt64(k string) int64
- func (v *Vector) ToString(k string) string
- func (v *Vector) ToStrings(k string) []string
- func (v *Vector) ToUint(k string) uint
- func (v *Vector) ToUint64(k string) uint64
- func (v *Vector) ToVector(k string) *Vector
- func (v *Vector) UnmarshalJSON(b []byte) error
- func (v *Vector) UnmarshalYAML(u func(interface{}) error) error
- type VectorItem
- type VisitorFunc
- type WriteFunc
- type YamlTransmitter
Constants ¶
const ( DefaultMaxPrefixPerNode = 10 DefaultMaxChildrenPerSparseNode = 8 )
Variables ¶
var ( JsonStore = &StoreMaker{"json", JsonStorer(regular)} JsonFStore = &StoreMaker{"jsonf", JsonStorer(indented)} )
var ErrNilPrefix = xrr.Xrror("Nil prefix passed into a method call")
var FunctionNotImplemented = xrr.Xrror("%s function not implemented for the %s store.").Out
var MalformedRetrievalStringError = xrr.Xrror("%s is malformed: %s").Out
var NoItemError = xrr.Xrror("No item with the prefix %s available.").Out
var ReaderRetrievalError = xrr.Xrror("unable to find readcloser: %s").Out
var SkipSubtree = xrr.Xrror("Skip this subtree")
var StdoutStore = &StoreMaker{"stdout", OutStore(os.Stdout)}
var YamlStore = &StoreMaker{"yaml", yamlStore}
Functions ¶
func SetStore ¶
func SetStore(fs ...*StoreMaker)
Types ¶
type BoolItem ¶
An interface for a specific bool type Item.
func NewBoolItem ¶
Creates a new BoolItem from the provided string key and boolean value.
type Float64Item ¶
An interface for a specific float64 type Item.
func NewFloat64Item ¶
func NewFloat64Item(key string, v float64) Float64Item
Creates a new Float64Item from the provided string key and float64 value.
type Int64Item ¶
An interface for a specific int64 type Item.
func NewInt64Item ¶
Creates a new Int64Item from the provided string key and int64 value.
type IntItem ¶
An interface for a specific int type Item.
func NewIntItem ¶
Creates a new IntItem from the provided string key and int value.
type Item ¶
type Item interface { Keyer Valuer Transmitter Cloner }
An interface for storing and transmitting single items composed of Keyer, Valuer, Transmitter, and Cloner interfaces.
func NewVectorItem ¶
Creates a new VectorItem from the provided string key and *Vector value.
type JsonTransmitter ¶
type JsonTransmitter interface { json.Marshaler json.Unmarshaler }
A json transmitter interface.
type Mtem ¶
type Mtem struct { Key string `json:"key"` Value interface{} `json:"value"` }
An intermediary unmarshaling type.
type Option ¶
type Option func(*Trie)
func MaxPrefixPerNode ¶
func WithPrefix ¶
type Retriever ¶
type Retriever struct {
// contains filtered or unexported fields
}
func NewRetriever ¶
func (*Retriever) RetrievalString ¶
func (*Retriever) SetRetrieval ¶
type Store ¶
type StoreFn ¶
func JsonStorer ¶
func JsonStorer(jm jsonMarshaler) StoreFn
type StoreMaker ¶
type Stores ¶
type Stores map[string]*StoreMaker
var AvailableStores Stores
func (Stores) Set ¶
func (s Stores) Set(fs ...*StoreMaker)
type StringItem ¶
An interface for a specific string type Item.
func NewStringItem ¶
func NewStringItem(key, v string) StringItem
Creates a new StringItem from the provided key and value.
type StringsItem ¶
An interface for a specific []string type Item.
func NewStringsItem ¶
func NewStringsItem(key string, v ...string) StringsItem
Creates a new StringsItem from the provided key and string values.
type Transmitter ¶
type Transmitter interface { JsonTransmitter YamlTransmitter }
An interface for managing transmission of values between formats
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
A trie constructed from https://github.com/tchap/go-patricia with a variety of changes and additions(and the opposite of optimisations).
func (*Trie) DeleteSubtree ¶
func (*Trie) MatchSubtree ¶
func (*Trie) Visit ¶
func (t *Trie) Visit(v VisitorFunc) error
func (*Trie) VisitPrefixes ¶
func (t *Trie) VisitPrefixes(p Prefix, v VisitorFunc) error
func (*Trie) VisitSubtree ¶
func (t *Trie) VisitSubtree(p Prefix, v VisitorFunc) error
type Uint64Item ¶
An interface for a specific uint64 type Item.
func NewUint64Item ¶
func NewUint64Item(key string, v uint64) Uint64Item
Creates a new Uint64Item from the provided string key and uint64 value.
type UintItem ¶
An interface for a specific uint type Item.
func NewUintItem ¶
Creates a new UintItem from the provided string key and uint value.
type Valuer ¶
type Valuer interface { Value() []byte Provided() interface{} Provide(interface{}) }
An interface for managing any type of value.
type Vector ¶
type Vector struct { *Trie // contains filtered or unexported fields }
A sync.Mutex bound struct that wraps a Trie holding package level Item.
func (*Vector) Reset ¶
func (v *Vector) Reset()
Clears the Vector of all Item, except those matching the internal "vector" key e.g. "vector.tag", "vector.id", etc et al.
func (*Vector) SetFloat64 ¶
/ Set a Float64Item with the provided key and float64 value.
func (*Vector) SetStrings ¶
Set a StringsItem with the provided key and string values.
func (*Vector) TemplateData ¶
Returns the Vector data as a map[string]interface{} suitable for use with text.Template or html.Template. Keys are undotted form(e.g. key.key becomes KeyKey).
func (*Vector) ToBool ¶
Return a boolean from a matching key. Storing a BoolItem is relatively faster, but will attempt to return a bool from a StringItem.
func (*Vector) ToFloat64 ¶
Return a float64 from a key matching a stored Float64Item. Storing a float64Item is relatively faster, but will attempt to return a float64 from a StringItem.
func (*Vector) ToInt ¶
Return an integer from a matching key. Storing an IntItem is relatively faster, but will attempt to return an int from a StringItem.
func (*Vector) ToInt64 ¶
Return an int64 from a matching key. Storing an Int64Item is relatively faster, but will attempt to return an int64 from a StringItem.
func (*Vector) ToStrings ¶
Return an array of strings from a matching key. Storing a StringsItem is relatively faster, but will attempt to return strings from a StringItem.
func (*Vector) ToUint ¶
Return an uint from a key matching a stored UintItem. Storing a UintItem is relatively faster, but will attempt to return a uint from a StringItem.
func (*Vector) ToUint64 ¶
Return an uint64 from a key matching a stored Uint64Item. Storing a Uint64Item is relatively faster, but will attempt to return a uint64 from a StringItem.
func (*Vector) UnmarshalYAML ¶
yaml.Unmarshaler
type VectorItem ¶
An interface for a specific Vector type Item, i.e store multiple vectors within a single vector.
type VisitorFunc ¶
type YamlTransmitter ¶
type YamlTransmitter interface { yaml.Marshaler yaml.Unmarshaler }
A yaml transmitter interface.