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

Uint key doesn't add to path #15

Closed
p7a opened this issue Jul 4, 2019 · 2 comments
Closed

Uint key doesn't add to path #15

p7a opened this issue Jul 4, 2019 · 2 comments

Comments

@p7a
Copy link

p7a commented Jul 4, 2019

Using diff between maps with uint as key type, returns a path without the key value.

Following code prints:
"[{delete [items ] 2 } {delete [items ] 3 }]"

type Order struct {
	ID    string       `diff:"id"`
	Items map[uint]uint `diff:"items"`
}

func main() {
	a := Order{
		ID: "1234",
		Items: map[uint]uint{10: 1,
			20: 2,
			30: 3,
			40: 4},
	}

	b := Order{
		ID: "1234",
		Items: map[uint]uint{10: 1,
			40: 4},
	}

	changelog, err := diff.Diff(a, b)
	if err != nil {
		fmt.Println("error")
	} else {
		fmt.Println(changelog)
	}
@p7a
Copy link
Author

p7a commented Jul 4, 2019

func idstring(v interface{}) string {
switch v.(type) {
case string:
return v.(string)
case int:
return strconv.Itoa(v.(int))
default:
return ""
}
}

why did you avoid to add more types to the function? seems like the problem

@purehyperbole
Copy link
Member

Thanks for raising the issue!

This should now be fixed on master.

@p7a p7a changed the title Uint key doesn't added to path Uint key doesn't add to path Dec 3, 2019
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