YaoApp / kun

The data structures for Gou framework

Home Page:https://yaoapps.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

map 报错cannot return value obtained from unexported field or method

wwsheng009 opened this issue · comments

当把复杂struct转换成map时,如果struct中有未暴露属性会导出panic.
比如说把gin.context中的request对象转换成map对象就会报错

/home/go/projects/yao/source/kun/any/map.go

for i := 0; i < reflectValues.NumField(); i++ {
                       
			name := share.GetTagName(typeOfS.Field(i), "json")
                       //导致panic,因为有对象未暴露
			valuesMap[name] = reflectValues.Field(i).Interface()
}

尝试以下处理后未报错

for i := 0; i < reflectValues.NumField(); i++ {
			field := typeOfS.Field(i)
			if field.PkgPath != "" {
				continue
			}
			name := share.GetTagName(field, "json")
			valuesMap[name] = reflectValues.Field(i).Interface()
}
```