cast
cast copied to clipboard
Question: Why not use indirect for map
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.
What do you mean by "friendlier result"?
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