Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllKeyStrings ¶
AllKeyStrings is a shorthand to iterate a map node and collect all the keys (and convert them to strings), returning them in a slice.
func Recover ¶
func Recover(fn func()) (err error)
Recover invokes a function within a panic-recovering context, and returns any raised fluent.Error values; any other values are re-panicked.
This can be useful for writing large blocks of code using fluent nodes, and handling any errors at once at the end.
Types ¶
type ListBuilder ¶
type ListBuildingClosure ¶
type ListBuildingClosure func(lb ListBuilder, vnb NodeBuilder)
ListBuildingClosure is the signiture of a function which builds a Node of kind list.
The ListBuilder parameter is used to accumulate the new Node for the duration of the function; and when the function returns, that builder will be invoked. (In other words, there's no need to call `Build` within the closure itself -- and correspondingly, note the lack of return value.)
Additional NodeBuilder handles are provided for building the values. These are used when handling typed Node implementations, since in that case they may contain behavior related to the type contracts. (For untyped nodes, this is degenerate: the 'vnb' builder is not distinct from the parent builder driving this closure.)
type ListIterator ¶
type MapBuildingClosure ¶
type MapBuildingClosure func(mb MapBuilder, knb NodeBuilder, vnb NodeBuilder)
MapBuildingClosure is the signiture of a function which builds a Node of kind map.
The MapBuilder parameter is used to accumulate the new Node for the duration of the function; and when the function returns, that builder will be invoked. (In other words, there's no need to call `Build` within the closure itself -- and correspondingly, note the lack of return value.)
Additional NodeBuilder handles are provided for building keys and values. These are used when handling typed Node implementations, since in that case they may contain behavior related to the type contracts. (For untyped nodes, this is degenerate: these builders are not distinct from the parent builder driving this closure.)
REVIEW : whether 'knb' is needed. Not sure, and there are other pending discussions on this. (It's mostly a concern about having a place to do validation on construction; but it's possible we can solve this without additional Nodes and Builders by making that validation the responsibility of the inside of the mb.Insert method; but will this compose well, and will it convey the appropriate times to do the validations correctly? Is 'knb' relevant even if that last question is 'no'? If a concern is to avoid double-validations, that argues for `mb.Insert(Node, Node)` over `mb.Insert(string, Node)`, but if avoiding double-validations, that means we already have a Node and don't need 'knb' to get one. ... Design!)
type MapIterator ¶
type Node ¶
type Node interface {
ReprKind() ipld.ReprKind
LookupString(path string) Node
Lookup(key Node) Node
LookupIndex(idx int) Node
MapIterator() MapIterator
ListIterator() ListIterator
Length() int
IsNull() bool
AsBool() bool
AsInt() int
AsFloat() float64
AsString() string
AsBytes() []byte
AsLink() ipld.Link
GetError() error
}
fluent.Node is an interface with all the same methods names as ipld.Node, but all of the methods return only the thing itself, and not error values -- which makes chaining calls easier.
The very first error value encountered will be stored, and can be viewed later. After an error is encountered, all subsequent lookup methods will silently return the same error-storing node. Any of the terminal scalar-returning methods will panic if an error is stored. (The fluent.Recover function can be used to nicely gather these panics.)
type NodeBuilder ¶
type NodeBuilder interface {
CreateMap(MapBuildingClosure) ipld.Node
AmendMap(MapBuildingClosure) ipld.Node
CreateList(ListBuildingClosure) ipld.Node
AmendList(ListBuildingClosure) ipld.Node
CreateNull() ipld.Node
CreateBool(bool) ipld.Node
CreateInt(int) ipld.Node
CreateFloat(float64) ipld.Node
CreateString(string) ipld.Node
CreateBytes([]byte) ipld.Node
CreateLink(ipld.Link) ipld.Node
}
func WrapNodeBuilder ¶
func WrapNodeBuilder(nb ipld.NodeBuilder) NodeBuilder