Skip to content

Latest commit

 

History

History
85 lines (67 loc) · 1.96 KB

README.md

File metadata and controls

85 lines (67 loc) · 1.96 KB

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    any
	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
        }
    }
}