Skip to content

Commit

Permalink
Add global Print() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Jan 19, 2019
1 parent afa9bdf commit afeb26a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 6 additions & 0 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dapper

import (
"io"
"os"
"reflect"
"strings"
)
Expand Down Expand Up @@ -83,3 +84,8 @@ func Write(w io.Writer, v interface{}) (int, error) {
func Format(v interface{}) string {
return defaultPrinter.Format(v)
}

// Print writes a pretty-printed representation of v to os.Stdout.
func Print(v interface{}) {
defaultPrinter.Write(os.Stdout, v)
}
7 changes: 2 additions & 5 deletions printer_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package dapper_test

import (
"fmt"

. "github.com/dogmatiq/dapper"
)

func ExampleFormat() {
func ExamplePrint() {
type TreeNode struct {
Name string
Value interface{}
Expand All @@ -29,8 +27,7 @@ func ExampleFormat() {
},
}

s := Format(v)
fmt.Println(s)
Print(v)

// output: dapper_test.TreeNode{
// Name: "root"
Expand Down

0 comments on commit afeb26a

Please sign in to comment.