我有以下代码:
func returnTheMap() map[string][]string{
myThing := getSomeValue()
}
Run Code Online (Sandbox Code Playgroud)
getSomeValue() 返回类型的东西 map[string]interface{}
但它始终在内部map[string][]string.
什么是设置myThing相同的最佳方式getSomeValue(),但类型map[string][]string?
我可以像这样制作一个新对象:
newMap := make(map[string][]string)
// cardTypeList is of type map[string]interface {}, must convert to map[string][]string
for k, v := range myThing {
newMap[k] = v.([]string)
}
Run Code Online (Sandbox Code Playgroud)
但有没有办法在这里做到这一点,或者有任何首选的方法来做到这一点?