1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/vendor/github.com/shurcooL/go-goon/goon.go
2017-10-03 14:43:55 -04:00

53 lines
1.3 KiB
Go

// Package goon is a deep pretty printer with Go-like notation. It implements the goon specification.
package goon
import (
"io"
"os"
"github.com/shurcooL/go/reflectsource"
)
// Dump dumps goons to stdout.
func Dump(a ...interface{}) (n int, err error) {
return os.Stdout.Write(bdump(a...))
}
// Sdump dumps goons to a string.
func Sdump(a ...interface{}) string {
return string(bdump(a...))
}
// Fdump dumps goons to a writer.
func Fdump(w io.Writer, a ...interface{}) (n int, err error) {
return w.Write(bdump(a...))
}
// DumpExpr dumps goon expressions to stdout.
//
// E.g., this:
//
// somethingImportant := 5
// DumpExpr(somethingImportant)
//
// Will print:
//
// somethingImportant = (int)(5)
func DumpExpr(a ...interface{}) (n int, err error) {
return os.Stdout.Write(bdumpNamed(reflectsource.GetParentArgExprAllAsString(), a...))
}
// SdumpExpr dumps goon expressions to a string.
func SdumpExpr(a ...interface{}) string {
return string(bdumpNamed(reflectsource.GetParentArgExprAllAsString(), a...))
}
// FdumpExpr dumps goon expressions to a writer.
func FdumpExpr(w io.Writer, a ...interface{}) (n int, err error) {
names := reflectsource.GetParentArgExprAllAsString()
if len(names) >= 1 {
names = names[1:] // First argument is the writer, skip it.
}
return w.Write(bdumpNamed(names, a...))
}