spf13 / cast

safe and easy casting from one type to another in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Why not use indirect for map

icbd opened this issue · comments

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