dot

package
v0.0.0-...-4b9bf86 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 8 Imported by: 9

Documentation

Overview

Package dot implements a container of named stringmaps.

Yes, it's just a tree of strings and Stringers - free of duplicate names.

And, yes, it's recursive. And, yes it's concurrency-safe. And, yes it carries stuff as You name it. And, yes it can also carry arbitrary Stringers - things which can name themselves. And, yes it supports concurrency via generic piping functions - found elsewhere.

Children can be obtained as map[string]string, and as sorted slice []string

Thus, it can be used as an iterated map "map[string]map[string]...map[string]string" or as an iterated slice "[]...[]string"

Any of it's elements has a name (=string) and (optionally) a map of named elements, the key's of which are strings, and the values are elements, which are strings which are the name of an (optional) map of named elements, the key's of which are strings, and the values are elements, which are strings which are the name of an (optional) map of named elements, the key's of which are strings, and the values are elements, which are strings which are the name of an (optional) map of named elements, the key's of which are strings, and the values are elements, ...

Such structure can be useful when information is acquired recursivlely such as by parsing some object (directory, template, URL, ...), which contains and 'reveals' additional information when being parsed/inspected.

Information, which 'reveals' additional information when being parsed/inspected.

...

Such can be used e.g. in selfdefining template structures Such may be extended to all kind's of types which are suitable as both key and value of a map.

This prototype has it's focus on type "string", as this is helpful in dynamic handling of template-driven processes.

Index

Constants

View Source
const ErrorID = ":" + ErrorName + ":"

ErrorID is the ID of of a node of type error

View Source
const ErrorName = "Error"

ErrorName is the name of a node-type error

Variables

This section is empty.

Functions

This section is empty.

Types

type AssignFriendly

type AssignFriendly interface {
	Assignss(vals ...string) *Dot           // Assign/overwrite Content with val - given as strings
	AssignSs(val ...[]string) *Dot          // Assign/overwrite Content with val - given as slices of strings
	AssignMs(val ...map[string]string) *Dot // Assign/overwrite Content with val - given as maps of strings
}

AssignFriendly - interface exposed for go doc only

type ChildFriendly

type ChildFriendly interface {
	// contains filtered or unexported methods
}

ChildFriendly - interface exposed for go doc only

type DeleteFriendly

type DeleteFriendly interface {
	Deletess(vals ...string) *Dot            // Delete/remove vals from Content - given as strings
	DeleteSs(vals ...[]string) *Dot          // Delete/remove val from Content - given as slices of strings
	DeleteMs(vals ...map[string]string) *Dot // Delete/remove val from Content - given as maps of strings
}

DeleteFriendly - interface exposed for go doc only

type Dot

type Dot struct {
	*tag.TagAny          // key - a Key Value Pair
	*lsm.LazyStringerMap // value(s) - an 'Anything' StringMap
	*sync.RWMutex        // public lock - concurency enabled!
	// contains filtered or unexported fields
}

Dot - a tree of named anythings - useful for agnostic template-driven text generation

"Templates are executed by applying them to a data structure. Annotations in the template refer to elements of the data structure (typically a field of a struct or a key in a map) to control execution and derive values to be displayed.

Execution of the template walks the structure and sets the cursor, represented by a period '.' and called "dot", to the value at the current location in the structure as execution proceeds."

quoted from `text/template/doc.go`

func New

func New(key string) *Dot

New returns what You need in order to keep a hand on me :-)

func Try

func Try(v interface{}) (*Dot, bool)

Try returns anything as a *Dot, or nil and false, iff no *Dot was given.

func (*Dot) A

func (d *Dot) A(vals ...string) string

A is a helper method for templates: Add value(s), and return an empty string

func (*Dot) AddMap

func (d *Dot) AddMap(key string, val ...map[string]string) *Dot

AddMap adds key to current dot d and adds content below this key using given variadic string-maps

func (*Dot) AddStringS

func (d *Dot) AddStringS(key string, val ...[]string) *Dot

AddStringS adds key to current dot d and adds content below this key using given variadic string-slices

func (*Dot) AddStrings

func (d *Dot) AddStrings(key string, val ...string) *Dot

AddStrings adds key to current dot d and adds content below this key using given variadic strings

func (*Dot) AssignMs

func (d *Dot) AssignMs(val ...map[string]string) *Dot

AssignMs adds to (or replaces with) content below current dot d using given variadic string-maps

func (*Dot) AssignSs

func (d *Dot) AssignSs(val ...[]string) *Dot

AssignSs adds to (or replaces with) content below current dot d using given variadic string-slices

func (*Dot) Assignss

func (d *Dot) Assignss(vals ...string) *Dot

Assignss adds to (or replaces with) content below current dot d using given variadic strings

func (*Dot) Back

func (d *Dot) Back() *Dot

Back returns the parent (or nil, if at root)

func (*Dot) Clone

func (d *Dot) Clone() *Dot

Clone returns a completely new Dot tree: a copy of d and it's entire subtree

func (*Dot) DeleteMs

func (d *Dot) DeleteMs(vals ...map[string]string) *Dot

DeleteMs deletes / removes content below current dot d using given variadic string-maps

func (*Dot) DeleteSs

func (d *Dot) DeleteSs(vals ...[]string) *Dot

DeleteSs deletes / removes content below current dot d using given variadic string-slices

func (*Dot) Deletess

func (d *Dot) Deletess(vals ...string) *Dot

Deletess deletes / removes content below current dot d using given variadic strings

func (*Dot) Dot

func (d *Dot) Dot() interface{}

Dot is a helper method for templates: Dot returns the value of the current dot.

func (*Dot) DotDot

func (d *Dot) DotDot(key, val string) *Dot

DotDot is a helper method for templates: Assign Key & Value to current dot.

func (*Dot) DotDotDots

func (d *Dot) DotDotDots() []*Dot

DotDotDots is a helper method for templates: Returns the entire subtree, depth first.

func (*Dot) DownS

func (d *Dot) DownS() []*Dot

DownS returns the children as a Dot-slice, sorted ascending bykey

func (*Dot) FprintTree

func (d *Dot) FprintTree(w io.Writer, pfx ...string) *Dot

FprintTree prints the tree to io.Writer, one line per node, each prefixed by prefix and indented with tab "\t"

func (*Dot) G

func (d *Dot) G(keys ...string) *Dot

G is a helper method for templates: Go down into (eventually new!) key(s) and return the final child dot (key).

func (*Dot) Home

func (d *Dot) Home() *Dot

Home returns the original home - just in case You lost it :-)

func (*Dot) Level

func (d *Dot) Level() int

Level returns the # of levels above - Root().Depth() == 0

func (*Dot) Path

func (d *Dot) Path() []*Dot

Path returns a slice from here up to the root Note: as the slice is returned bottom-up, may like to reverse it :-)

func (*Dot) PathBase

func (d *Dot) PathBase() string

PathBase - func path.Base(path string) string

func (*Dot) PathClean

func (d *Dot) PathClean() string

PathClean - func path.Clean(path string) string

func (*Dot) PathDir

func (d *Dot) PathDir() string

PathDir - func path.Dir(path string) string

func (*Dot) PathDown

func (d *Dot) PathDown() string

PathDown returns the path from Root to here as a path.Join'ed string. Note: Intentionally, path.Clean is neither applied to components nor to the result, as this might make components such as ".." 'disappear'; but path.Clean is applied to empty nodes in order to gain a "." being joined!

func (*Dot) PathExt

func (d *Dot) PathExt() string

PathExt - func path.Ext(path string) string

func (*Dot) PathIsAbs

func (d *Dot) PathIsAbs() bool

PathIsAbs - func path.IsAbs(path string) bool

func (*Dot) PathJoin

func (d *Dot) PathJoin(elem ...string) string

PathJoin - func path.Join(elem ...string) string

Note: joins elem... to Dot

func (*Dot) PathJoinThese

func (d *Dot) PathJoinThese(elem ...string) string

PathJoinThese - func path.Join(elem ...string) string

Note: joins elem... - does not consider Dot

func (*Dot) PathMatch

func (d *Dot) PathMatch(pattern string) (matched bool, err error)

PathMatch - func path.Match(pattern, name string) (matched bool, err error)

func (*Dot) PrintTree

func (d *Dot) PrintTree(prefix ...string) *Dot

PrintTree prints the tree to os.Stdout, one line per node, each prefixed by prefix and indented with tab "\t"

func (*Dot) PutOut

func (d *Dot) PutOut(msg ...interface{}) *Dot

PutOut prints msg's on a line to out()

func (*Dot) Root

func (d *Dot) Root() *Dot

Root goes all the way Up() and returns the root - just in case You lost it :-)

Note: usually, Root == Home. Alas: operations (such as Remove subtree) may invalidate this.

func (*Dot) SeeError

func (d *Dot) SeeError(sender, place string, err error) bool

SeeError - If err!=nil, attach an error below "Error:" of d, and return true

func (*Dot) SeeNotOk

func (d *Dot) SeeNotOk(sender, place string, ok bool, complain string) bool

SeeNotOk - If ok!=true, attach a not-ok complain below "Error:" of d, and return true

func (*Dot) Set

func (d *Dot) Set(vals ...string) *Dot

Set adds (or replaces) content below current dot d using given variadic strings

func (*Dot) SetM

func (d *Dot) SetM(val ...map[string]string) *Dot

SetM adds (or replaces) content below current dot d using given variadic string-maps

func (*Dot) SetOutput

func (d *Dot) SetOutput(output io.Writer) *Dot

SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.

func (*Dot) SetS

func (d *Dot) SetS(val ...[]string) *Dot

SetS adds (or replaces) content below current dot d using given variadic string-slices

func (*Dot) UnlockedAdd

func (d *Dot) UnlockedAdd(key string, val ...string) (interface{}, bool)

UnlockedAdd is a helper method and is exported only for use by the function library "do/dot". It adds key to d, and adds variadic strings below key, and returns child "key"

Note: It's 2nd arg (bool) intentionally avoids usage from templates!

Other clients must behave as if this method is not exported!

func (*Dot) UnlockedGet

func (d *Dot) UnlockedGet(key string) (interface{}, bool)

UnlockedGet is a helper method and is exported only for use by the function library "do/dot". It returns the (eventually new!) child (key)

Note: It's 2nd arg (bool) intentionally avoids usage from templates!

Other clients must behave as if this method is not exported!

func (*Dot) Up

func (d *Dot) Up() *Dot

Up returns the parent (or nil, if at root)

func (*Dot) WalkBreadth1st

func (d *Dot) WalkBreadth1st(wf WalkFunc) *Dot

WalkBreadth1st applies a given WalkFunc wf in breadth-first order

func (*Dot) WalkDepth1st

func (d *Dot) WalkDepth1st(wf WalkFunc) *Dot

WalkDepth1st applies a given WalkFunc wf in depth-first order

type DotS

type DotS []Friendly

DotS implements sort.Interface

func (DotS) Len

func (k DotS) Len() int

Len implements sort.Interface

func (DotS) Less

func (k DotS) Less(i, j int) bool

Less implements sort.Interface

func (DotS) Swap

func (k DotS) Swap(i, j int)

Swap implements sort.Interface

type ErrorFriendly

type ErrorFriendly interface {
	SeeError(sender, place string, err error) bool
	SeeNotOk(sender, place string, ok bool, complain string) bool
}

ErrorFriendly - interface exposed for go doc only

type Friendly

type Friendly interface {
	tag.Friendly      // via "container/.../tag/..."
	lsm.Friendly      // via "container/.../lsm"
	StringFriendly    // dot.go: Set..., Assign..., Delete...
	ChildFriendly     // children.go: lookupDot getChild
	NavigatorFriendly // navigate.go: Up Root Path DownS
	PrinterFriendly   // print.go: PrintTree
	ErrorFriendly     // => dot!	error.go
	OutputFriendly    // output.go
	GoFriendly        // dot.go
}

Friendly - interface exposed for go doc only shows the composition as interface

type GoFriendly

type GoFriendly interface {
	// helper for templates:
	A(vals ...string) string     // Add values, and return an empty string
	G(keys ...string) *Dot       // Go into key(s)
	DotDot(key, val string) *Dot // Assign a Key Value Pair
	Dot() interface{}            // The value of the current dot
	DotDotDots() []*Dot          // The entire subtree, depth first
	// helper for "do/dot"
	UnlockedGet(key string) (interface{}, bool)
	UnlockedAdd(key string, val ...string) (interface{}, bool)
}

GoFriendly - interface exposed for go doc only

type NavigatorFriendly interface {
	Back() *Dot    // returns the parent (or nil, if at root)
	Up() *Dot      // returns the parent (or nil, if at root) (same as Back())
	Home() *Dot    // returns the original home - just in case You lost it :-)
	Root() *Dot    // goes all the way Up() and returns the root (of subtree)
	Path() []*Dot  // returns a slice from here up to the root
	DownS() []*Dot // returns the children as a Dot-slice, sorted ascending bykey
	Level() int    // returns the # of levels above - Root().Depth() == 0
	// contains filtered or unexported methods
}

NavigatorFriendly - interface exposed for go doc only

type OutputFriendly

type OutputFriendly interface {
	SetOutput(output io.Writer) *Dot // sets the destination for usage and error messages. If output is nil, os.Stderr is used.
	PutOut(msg ...interface{}) *Dot  // prints msg's on a line to out()
	// contains filtered or unexported methods
}

OutputFriendly - interface exposed for go doc only

type PrinterFriendly

type PrinterFriendly interface {
	PrintTree(prefix ...string) *Dot // prints the tree, one line per node, each prefixed by prefix and indented with tab "\t"
}

PrinterFriendly - interface exposed for go doc only

type PrivacyFriendly

type PrivacyFriendly interface {
	// contains filtered or unexported methods
}

PrivacyFriendly - interface exposed for go doc only

type SetableFriendly

type SetableFriendly interface {
	Set(vals ...string) *Dot            // Set/replace Content with val - given as strings
	SetS(val ...[]string) *Dot          // Set/replace Content with val - given as slices of strings
	SetM(val ...map[string]string) *Dot // Set/replace Content with val - given as maps of strings
}

SetableFriendly - interface exposed for go doc only

type StringFriendly

type StringFriendly interface {
	SetableFriendly // set.go: Set/replace Content: Set SetS SetM
	AssignFriendly  // assign.go: Add/overwrite Content: Assignss AssignSs AssignMs
	UserFriendly    // add.go: AddMap AddStrings AddStringS
	DeleteFriendly  // delete.go: Delete/remove vals from Content: Deletes, DeleteS, DeleteM
	PrivacyFriendly // content.go: add addM

}

StringFriendly - interface exposed for go doc only

type UserFriendly

type UserFriendly interface {
	AddStrings(key string, val ...string) *Dot         // adds key to d, and adds variadic strings below key
	AddStringS(key string, val ...[]string) *Dot       // adds key to d, and adds slices below key
	AddMap(key string, vals ...map[string]string) *Dot // adds key to d, and adds map(s) below key
}

UserFriendly - interface exposed for go doc only

type WalkFunc

type WalkFunc func(d *Dot)

WalkFunc is the signature of a Walk function.

Jump to

Keyboard shortcuts

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