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

When Bool type = false, is missing from Type:create #98

Open
CIpherWGO opened this issue Feb 16, 2023 · 1 comment
Open

When Bool type = false, is missing from Type:create #98

CIpherWGO opened this issue Feb 16, 2023 · 1 comment

Comments

@CIpherWGO
Copy link

CIpherWGO commented Feb 16, 2023

Hi

Test code using go 1.20:

type Test struct {
	ID   int64  `diff:"id,identifier"`
	Bool bool   `diff:"bool"`
	Test string `diff:"test"`
}

a := []Test{{ID: 1, Bool: true, Test: "Bool set to true"}}

b := []Test{{ID: 2, Bool: false, Test: "Bool set to false"}}

changelog, err := diff.Diff(a, b)

if err != nil {
	fmt.Println(err)
	return
}

fmt.Printf("%+v\n", changelog)

Gives:

  {Type:create Path:[2 id] From:<nil> To:2 parent:<nil>} {Type:create Path:[2 test] From:<nil> To:Bool set to false parent:<nil>}]

Field Bool is missing from create. Should also have:

  {Type:create Path:[2 bool] From:<nil> To:false parent:<nil>}

Any help is appreciated!

Thanks.

@stevemil00
Copy link

I'm guessing this problem is related:

package main

import (
	"fmt"

	"github.com/r3labs/diff"
)

func main() {
	type Whatever struct {
		Enabled bool
	}
	old := map[string]Whatever{"in-errors": {false}}
	new := map[string]Whatever{}
	changes, err := diff.Diff(old, new)
	if err != nil {
		fmt.Printf("error diffing old (%#v) and new (%#v): %s", old, new, err.Error())
		return
	}
	fmt.Printf("differences from old (%#v) to new (%#v): %#v", old, new, changes)
}

which produces:

differences from old (map[string]main.Whatever{"in-errors":main.Whatever{Enabled:false}}) to new (map[string]main.Whatever{}): diff.Changelog(nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants