goon

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 10 Imported by: 1

README

goon

Build Status GoDoc

本库修改自https://github.com/shurcooL/goon, 由于上面的库常久不更新, 并且我需要做一些小的修改满足需求, 所以fork了自用, 仍采用MIT许可.

主要修改有:

  1. 增加goon="-"的tag让我们可以对结构体手动控制哪些字段不需要
  2. 对XXX_开头的字段全都去掉, 这些是protobuf中比较多余的字段
  3. 对golang特有的枚举做支持

Package goon is a deep pretty printer with Go-like notation. It implements the goon specification.

Installation

go get -u github.com/shurcooL/go-goon

Examples

x := Lang{
	Name: "Go",
	Year: 2009,
	URL:  "http",
	Inner: &Inner{
		Field1: "Secret!",
	},
}

goon.Dump(x)

// Output:
// (Lang)(Lang{
// 	Name: (string)("Go"),
// 	Year: (int)(2009),
// 	URL:  (string)("http"),
// 	Inner: (*Inner)(&Inner{
// 		Field1: (string)("Secret!"),
// 		Field2: (int)(0),
// 	}),
// })
items := []int{1, 2, 3}

goon.DumpExpr(len(items))

// Output:
// len(items) = (int)(3)
adderFunc := func(a int, b int) int {
	c := a + b
	return c
}

goon.DumpExpr(adderFunc)

// Output:
// adderFunc = (func(int, int) int)(func(a int, b int) int {
// 	c := a + b
// 	return c
// })

Directories

Path Synopsis
bypass Package bypass allows bypassing reflect restrictions on accessing unexported struct fields.

Attribution

go-goon source was based on the existing source of go-spew by Dave Collins.

License

Documentation

Overview

Package goon is a deep pretty printer with Go-like notation. It implements the goon specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(a ...interface{}) (n int, err error)

Dump dumps goons to stdout.

func DumpExpr

func DumpExpr(a ...interface{}) (n int, err error)

DumpExpr dumps goon expressions to stdout.

E.g., this:

somethingImportant := 5
DumpExpr(somethingImportant)

Will print:

somethingImportant = (int)(5)

func Fdump

func Fdump(w io.Writer, a ...interface{}) (n int, err error)

Fdump dumps goons to a writer.

func FdumpExpr

func FdumpExpr(w io.Writer, a ...interface{}) (n int, err error)

FdumpExpr dumps goon expressions to a writer.

func Sdump

func Sdump(a ...interface{}) string

Sdump dumps goons to a string.

func SdumpExpr

func SdumpExpr(a ...interface{}) string

SdumpExpr dumps goon expressions to a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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