Documentation
¶
Overview ¶
qp helps to quickly build IPLD nodes.
It contains top-level Build funcs, such as BuildMap and BuildList, which return the final node as well as an error.
Underneath, one can use a number of Assemble functions to construct basic nodes, such as String or Int.
Finally, functions like MapEntry and ListEntry allow inserting into maps and lists.
These all use the same IPLD datamodel interfaces such as NodePrototype and NodeAssembler, but with some magic to reduce verbosity.
Example ¶
package main import ( "os" "github.com/ipld/go-ipld-prime/codec/dagjson" "github.com/ipld/go-ipld-prime/datamodel" "github.com/ipld/go-ipld-prime/fluent/qp" "github.com/ipld/go-ipld-prime/node/basicnode" ) func main() { n, err := qp.BuildMap(basicnode.Prototype.Any, 4, func(ma datamodel.MapAssembler) { qp.MapEntry(ma, "some key", qp.String("some value")) qp.MapEntry(ma, "another key", qp.String("another value")) qp.MapEntry(ma, "nested map", qp.Map(2, func(ma datamodel.MapAssembler) { qp.MapEntry(ma, "deeper entries", qp.String("deeper values")) qp.MapEntry(ma, "more deeper entries", qp.String("more deeper values")) })) qp.MapEntry(ma, "nested list", qp.List(2, func(la datamodel.ListAssembler) { qp.ListEntry(la, qp.Int(1)) qp.ListEntry(la, qp.Int(2)) })) }) if err != nil { panic(err) } dagjson.Encode(n, os.Stdout) }
Output: {"another key":"another value","nested list":[1,2],"nested map":{"deeper entries":"deeper values","more deeper entries":"more deeper values"},"some key":"some value"}
Index ¶
- func BuildList(np datamodel.NodePrototype, sizeHint int64, fn func(datamodel.ListAssembler)) (_ datamodel.Node, err error)
- func BuildMap(np datamodel.NodePrototype, sizeHint int64, fn func(datamodel.MapAssembler)) (_ datamodel.Node, err error)
- func ListEntry(la datamodel.ListAssembler, fn Assemble)
- func MapEntry(ma datamodel.MapAssembler, k string, fn Assemble)
- type Assemble
- func Bool(b bool) Assemble
- func Bytes(p []byte) Assemble
- func Float(f float64) Assemble
- func Int(i int64) Assemble
- func Link(l datamodel.Link) Assemble
- func List(sizeHint int64, fn func(datamodel.ListAssembler)) Assemble
- func Map(sizeHint int64, fn func(datamodel.MapAssembler)) Assemble
- func Node(n datamodel.Node) Assemble
- func Null() Assemble
- func String(s string) Assemble
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildList ¶
func BuildList(np datamodel.NodePrototype, sizeHint int64, fn func(datamodel.ListAssembler)) (_ datamodel.Node, err error)
func BuildMap ¶
func BuildMap(np datamodel.NodePrototype, sizeHint int64, fn func(datamodel.MapAssembler)) (_ datamodel.Node, err error)
func ListEntry ¶
func ListEntry(la datamodel.ListAssembler, fn Assemble)
Types ¶
type Assemble ¶
type Assemble = func(datamodel.NodeAssembler)
Click to show internal directories.
Click to hide internal directories.