qp

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 2 Imported by: 24

Documentation

Overview

qp is similar to fluent/quip, but with a bit more magic.

Example
n, err := qp.BuildMap(basicnode.Prototype.Any, 4, func(ma ipld.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 ipld.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 ipld.ListAssembler) {
		qp.ListEntry(la, qp.Int(1))
		qp.ListEntry(la, qp.Int(2))
	}))
})
if err != nil {
	panic(err)
}
dagjson.Encode(n, os.Stdout)
Output:

{
	"some key": "some value",
	"another key": "another value",
	"nested map": {
		"deeper entries": "deeper values",
		"more deeper entries": "more deeper values"
	},
	"nested list": [
		1,
		2
	]
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildList

func BuildList(np ipld.NodePrototype, sizeHint int64, fn func(ipld.ListAssembler)) (_ ipld.Node, err error)

func BuildMap

func BuildMap(np ipld.NodePrototype, sizeHint int64, fn func(ipld.MapAssembler)) (_ ipld.Node, err error)

func ListEntry

func ListEntry(la ipld.ListAssembler, fn Assemble)

func MapEntry

func MapEntry(ma ipld.MapAssembler, k string, fn Assemble)

Types

type Assemble

type Assemble = func(ipld.NodeAssembler)

func Bool

func Bool(b bool) Assemble

func Bytes

func Bytes(p []byte) Assemble

func Float

func Float(f float64) Assemble

func Int

func Int(i int64) Assemble
func Link(l ipld.Link) Assemble

func List

func List(sizeHint int64, fn func(ipld.ListAssembler)) Assemble

func Map

func Map(sizeHint int64, fn func(ipld.MapAssembler)) Assemble

func Node

func Node(n ipld.Node) Assemble

func Null

func Null() Assemble

func String

func String(s string) Assemble

Jump to

Keyboard shortcuts

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