Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore fields using a tag #98

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import (
"html"
"net/http"

"github.com/davecgh/go-spew/spew"
"github.com/coreyog/go-spew/spew"
)

func handler(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion spew/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"reflect"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/coreyog/go-spew/spew"
)

// custom type to test Stinger interface on non-pointer receiver.
Expand Down
17 changes: 15 additions & 2 deletions spew/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,26 @@ func (d *dumpState) dump(v reflect.Value) {
vt := v.Type()
numFields := v.NumField()
for i := 0; i < numFields; i++ {
d.indent()
vtf := vt.Field(i)
tag := vtf.Tag.Get("spew")
if tag == "-" {
continue
}
d.indent()
d.w.Write([]byte(vtf.Name))
d.w.Write(colonSpaceBytes)
d.ignoreNextIndent = true
d.dump(d.unpackValue(v.Field(i)))
if i < (numFields - 1) {

hasAnotherFieldToWrite := false
for j := i + 1; j < numFields; j++ {
vtf = vt.Field(j)
tag = vtf.Tag.Get("spew")
if tag != "-" {
hasAnotherFieldToWrite = true
}
}
if i < (numFields-1) && hasAnotherFieldToWrite {
d.w.Write(commaNewlineBytes)
} else {
d.w.Write(newlineBytes)
Expand Down
2 changes: 1 addition & 1 deletion spew/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import (
"testing"
"unsafe"

"github.com/davecgh/go-spew/spew"
"github.com/coreyog/go-spew/spew"
)

// dumpTest is used to describe a test to be performed against the Dump method.
Expand Down
2 changes: 1 addition & 1 deletion spew/dumpcgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package spew_test
import (
"fmt"

"github.com/davecgh/go-spew/spew/testdata"
"github.com/coreyog/go-spew/spew/testdata"
)

func addCgoDumpTests() {
Expand Down
2 changes: 1 addition & 1 deletion spew/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package spew_test
import (
"fmt"

"github.com/davecgh/go-spew/spew"
"github.com/coreyog/go-spew/spew"
)

type Flag int
Expand Down
2 changes: 1 addition & 1 deletion spew/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import (
"testing"
"unsafe"

"github.com/davecgh/go-spew/spew"
"github.com/coreyog/go-spew/spew"
)

// formatterTest is used to describe a test to be performed against NewFormatter.
Expand Down
11 changes: 10 additions & 1 deletion spew/spew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/coreyog/go-spew/spew"
)

// spewFunc is used to identify which public function of the spew package or
Expand Down Expand Up @@ -154,6 +154,13 @@ func initSpewTests() {
dt := depthTester{indirCir1{nil}, [1]string{"arr"}, []string{"slice"},
map[string]int{"one": 1}}

type ignoreTester struct {
visible bool
invisible bool `spew:"-"`
}

it := ignoreTester{true, false}

// Variable for tests on types which implement error interface.
te := customError(10)

Expand All @@ -179,6 +186,8 @@ func initSpewTests() {
{scsDefault, fSprint, "", complex(-1, -2), "(-1-2i)"},
{scsDefault, fSprintf, "%v", complex(float32(-3), -4), "(-3-4i)"},
{scsDefault, fSprintln, "", complex(float64(-5), -6), "(-5-6i)\n"},
{scsDefault, fCSFdump, "", it, "(spew_test.ignoreTester) {\n" +
" visible: (bool) true\n}\n"},
{scsNoMethods, fCSFprint, "", ts, "test"},
{scsNoMethods, fCSFprint, "", &ts, "<*>test"},
{scsNoMethods, fCSFprint, "", tps, "test"},
Expand Down