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

Question: Why not use indirect for map #105

Open
icbd opened this issue Oct 10, 2020 · 2 comments
Open

Question: Why not use indirect for map #105

icbd opened this issue Oct 10, 2020 · 2 comments

Comments

@icbd
Copy link

icbd commented Oct 10, 2020

package main

import (
	"fmt"
	"github.com/spf13/cast"
)

func main() {
	a := map[string]string{"hello": "123"}

	r := cast.ToStringMapInt(a)
	fmt.Printf("%T %#v\n", r, r)

	r = cast.ToStringMapInt(&a)
	fmt.Printf("%T %#v\n", r, r)
}

//OUTPUT:
//map[string]int map[string]int{"hello":123}
//map[string]int map[string]int{}

If ToStringMapInt does indirect as well, then the ToStringMapInt method will have a friendlier result.

@bep
Copy link
Collaborator

bep commented Oct 10, 2020

What do you mean by "friendlier result"?

@icbd
Copy link
Author

icbd commented Oct 15, 2020

What do you mean by "friendlier result"?

a := map[string]string{"hello": "123"},
If cast can help me deal with the pointer, I'd be free to pass in a or &a.

Method indirect is not called when processing map. Can you please explain why? Thanks

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