data

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: MIT Imports: 13 Imported by: 0

README

data

General purpose custom data containment for use with the Go programming language.

Item

An interface (and package default specific structure) for managing Key & Value for data in addition to providing facility for transmission and cloning.

Trie

A trie constructed from https://github.com/tchap/go-patricia with a variety of changes and additions(and more likely the opposite of optimisations).

Vector

A sync.Mutex bound struct wrapping an Item Trie with customized control.

Store

A structure for managing Vectors across varied formats(e.g. json, yaml, etc.).

Documentation

Overview

Package data contains generalized data management tactics & strategies. Currently this package provides four interrelated structures:

  • 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

View Source
const (
	DefaultMaxPrefixPerNode         = 10
	DefaultMaxChildrenPerSparseNode = 8
)

Variables

View Source
var (
	JsonStore  = &StoreMaker{"json", JsonStorer(regular)}
	JsonFStore = &StoreMaker{"jsonf", JsonStorer(indented)}
)
View Source
var ErrNilPrefix = xrr.Xrror("Nil prefix passed into a method call")
View Source
var FunctionNotImplemented = xrr.Xrror("%s function not implemented for the %s store.").Out
View Source
var MalformedRetrievalStringError = xrr.Xrror("%s is malformed: %s").Out
View Source
var NoItemError = xrr.Xrror("No item with the prefix %s available.").Out
View Source
var ReaderRetrievalError = xrr.Xrror("unable to find readcloser: %s").Out
View Source
var SkipSubtree = xrr.Xrror("Skip this subtree")
View Source
var StdoutStore = &StoreMaker{"stdout", OutStore(os.Stdout)}
View Source
var UnavailableStoreError = xrr.Xrror("No store with key: %s").Out
View Source
var YamlStore = &StoreMaker{"yaml", yamlStore}

Functions

func Exist

func Exist(path string)

func Open

func Open(path string) (*os.File, error)

func SetStore

func SetStore(fs ...*StoreMaker)

Types

type BoolItem

type BoolItem interface {
	Item
	ToBool() bool
	SetBool(bool)
}

An interface for a specific bool type Item.

func NewBoolItem

func NewBoolItem(key string, v bool) BoolItem

Creates a new BoolItem from the provided string key and boolean value.

type Cloner

type Cloner interface {
	Clone() Item
}

An interface for encapsulating item cloning.

type Float64Item

type Float64Item interface {
	Item
	ToFloat64() float64
	SetFloat(float64)
}

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 InFunc

type InFunc func(string, int64, io.ReadCloser) (*Vector, error)

type Int64Item

type Int64Item interface {
	Item
	ToInt64() int64
	SetInt64(int)
}

An interface for a specific int64 type Item.

func NewInt64Item

func NewInt64Item(key string, v int64) Int64Item

Creates a new Int64Item from the provided string key and int64 value.

type IntItem

type IntItem interface {
	Item
	ToInt() int
	SetInt(int)
}

An interface for a specific int type Item.

func NewIntItem

func NewIntItem(key string, v int) IntItem

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 KeyedItem

func KeyedItem(k string) Item

Returns an empty item with the provided key.

func NewVectorItem

func NewVectorItem(key string, v *Vector) Item

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 Keyer

type Keyer interface {
	Key() string
	KeyUndotted() string
	NewKey(string)
}

A string key management 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 MaxChildrenPerSparseNode

func MaxChildrenPerSparseNode(value int) Option

func MaxPrefixPerNode

func MaxPrefixPerNode(value int) Option

func WithPrefix

func WithPrefix(p string) Option

type OutFunc

type OutFunc func(*Vector, io.WriteCloser) ([]string, error)

type Prefix

type Prefix []byte

type ReadFunc

type ReadFunc func(*Retriever) (io.ReadCloser, int64, error)

type Retriever

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

func NewRetriever

func NewRetriever(with ...string) *Retriever

func (*Retriever) Retrieval

func (r *Retriever) Retrieval() []string

func (*Retriever) RetrievalString

func (r *Retriever) RetrievalString() string

func (*Retriever) SetRetrieval

func (r *Retriever) SetRetrieval(s []string)

type Store

type Store interface {
	Read([]byte) (int, error)
	In() (*Vector, error)
	Swap(*Vector)
	Out() (*Vector, error)
	Write([]byte) (int, error)
}

func GetStore

func GetStore(k string, r []string) (Store, error)

func NewStore

func NewStore(rfn ReadFunc, ifn InFunc, ofn OutFunc, wfn WriteFunc, rs ...string) Store

type StoreFn

type StoreFn func([]string) Store

func JsonStorer

func JsonStorer(jm jsonMarshaler) StoreFn

func OutStore

func OutStore(out *os.File) StoreFn

type StoreMaker

type StoreMaker struct {
	Key string
	Fn  StoreFn
}

type Stores

type Stores map[string]*StoreMaker
var AvailableStores Stores

func (Stores) Get

func (s Stores) Get(k string, r []string) (Store, error)

func (Stores) Set

func (s Stores) Set(fs ...*StoreMaker)

type StringItem

type StringItem interface {
	Item
	ToString() string
	SetString(string)
}

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

type StringsItem interface {
	Item
	ToStrings() []string
	SetStrings(...string)
}

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 NewTrie

func NewTrie(options ...Option) *Trie

func (*Trie) Delete

func (t *Trie) Delete(p Prefix) bool

func (*Trie) DeleteSubtree

func (t *Trie) DeleteSubtree(p Prefix) bool

func (*Trie) Item

func (t *Trie) Item() Item

func (*Trie) Match

func (t *Trie) Match(p Prefix) bool

func (*Trie) MatchSubtree

func (t *Trie) MatchSubtree(p Prefix) bool

func (*Trie) Tagged

func (t *Trie) Tagged() string

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

type Uint64Item interface {
	Item
	ToUint64() uint64
	SetUint64(uint64)
}

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

type UintItem interface {
	Item
	ToUint() uint
	SetUint(uint)
}

An interface for a specific uint type Item.

func NewUintItem

func NewUintItem(key string, v uint) UintItem

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 New

func New(tag string, o ...Option) *Vector

func (*Vector) Blacklist

func (v *Vector) Blacklist(keys ...string)

func (*Vector) Clear

func (v *Vector) Clear()

Clears the Vector of all Item.

func (*Vector) Clone

func (v *Vector) Clone(except ...string) *Vector

func (*Vector) CloneAs

func (v *Vector) CloneAs(tag string, except ...string) *Vector

func (*Vector) Get

func (v *Vector) Get(k string) Item

func (*Vector) Keys

func (v *Vector) Keys() []string

func (*Vector) List

func (v *Vector) List(except ...string) []Item

Returns a list of Item, EXCEPT those matching the provided key strings.

func (*Vector) MarshalJSON

func (v *Vector) MarshalJSON() ([]byte, error)

json.Marshaler

func (*Vector) MarshalYAML

func (v *Vector) MarshalYAML() (interface{}, error)

yaml.Marshaler

func (*Vector) Match

func (v *Vector) Match(k string) []Item

func (*Vector) Merge

func (v *Vector) Merge(vs ...*Vector)

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

func (v *Vector) Retag(t string)

func (*Vector) Set

func (v *Vector) Set(i ...Item)

func (*Vector) SetBool

func (v *Vector) SetBool(k string, vi bool)

Set a BoolItem with the provided key and boolean value.

func (*Vector) SetFloat64

func (v *Vector) SetFloat64(k string, vi float64)

/ Set a Float64Item with the provided key and float64 value.

func (*Vector) SetInt

func (v *Vector) SetInt(k string, vi int)

Set an IntItem with the provided key and integer value.

func (*Vector) SetInt64

func (v *Vector) SetInt64(k string, vi int64)

Set an Int64Item with the provided key and int64 value.

func (*Vector) SetString

func (v *Vector) SetString(k, vi string)

Set a StringItem with the provided key and value.

func (*Vector) SetStrings

func (v *Vector) SetStrings(k string, vi ...string)

Set a StringsItem with the provided key and string values.

func (*Vector) SetUint

func (v *Vector) SetUint(k string, vi uint)

Set an UintItem with the provided key and uint value.

func (*Vector) SetUint64

func (v *Vector) SetUint64(k string, vi uint64)

Set an Uint64Item with the provided key and uint64 value.

func (*Vector) SetVector

func (v *Vector) SetVector(k string, vi *Vector)

Set a VectorItem with the provided key and *Vector value.

func (*Vector) Tag

func (v *Vector) Tag() string

func (*Vector) TemplateData

func (v *Vector) TemplateData() map[string]interface{}

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

func (v *Vector) ToBool(k string) bool

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

func (v *Vector) ToFloat64(k string) float64

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

func (v *Vector) ToInt(k string) int

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

func (v *Vector) ToInt64(k string) int64

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

func (v *Vector) ToString(k string) string

Return a string from key matching a stored StringItem.

func (*Vector) ToStrings

func (v *Vector) ToStrings(k string) []string

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

func (v *Vector) ToUint(k string) uint

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

func (v *Vector) ToUint64(k string) uint64

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

func (v *Vector) ToVector(k string) *Vector

Return a *Vector from a key matching a stored VectorItem.

func (*Vector) UnmarshalJSON

func (v *Vector) UnmarshalJSON(b []byte) error

json.Unmarshaler

func (*Vector) UnmarshalYAML

func (v *Vector) UnmarshalYAML(u func(interface{}) error) error

yaml.Unmarshaler

type VectorItem

type VectorItem interface {
	Item
	ToVector() *Vector
	SetVector(*Vector)
}

An interface for a specific Vector type Item, i.e store multiple vectors within a single vector.

type VisitorFunc

type VisitorFunc func(Prefix, Item) error

type WriteFunc

type WriteFunc func(*Vector) (io.WriteCloser, error)

type YamlTransmitter

type YamlTransmitter interface {
	yaml.Marshaler
	yaml.Unmarshaler
}

A yaml transmitter interface.

Jump to

Keyboard shortcuts

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