dogmatiq / dapper

A pretty-printer for Go values with minimalistic output.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dapper

Dapper is a pretty-printer for Go values.

Documentation Latest Version Build Status Code Coverage

Dapper is not intended to be used directly as a debugging tool, but as a library for applications that need to describe Go values to humans, such as testing frameworks.

Some features and design goals include:

  • Concise formatting, without type ambiguity
  • Deterministic output, useful for generating diffs using standard tools
  • A filter system for producing customized output on a per-value basis

Example

This example renders a basic tree structure. Note that the output only includes type names where the value's type can not be inferred from the context.

Code

package main

import (
	"fmt"
	"github.com/dogmatiq/dapper"
)

type TreeNode struct {
	Name     string
	Value    interface{}
	Children []*TreeNode
}

type NodeValue struct{}

func main() {
	v := TreeNode{
		Name: "root",
		Children: []*TreeNode{
			{
				Name:  "branch #1",
				Value: 100,
			},
			{
				Name:  "branch #2",
				Value: NodeValue{},
			},
		},
	}

	dapper.Print(v)
}

Output

main.TreeNode{
    Name:     "root"
    Value:    nil
    Children: {
        {
            Name:     "branch #1"
            Value:    int(100)
            Children: nil
        }
        {
            Name:     "branch #2"
            Value:    main.NodeValue{}
            Children: nil
        }
    }
}

About

A pretty-printer for Go values with minimalistic output.

License:MIT License


Languages

Language:Go 99.8%Language:Makefile 0.2%