golang fails to parse json for reflection created object
问题 I try to write simple message protocol in go and i've encountered a problem. I have a lot of message types and i want to have a dictionary like this to manipulate with messages: var dict map[reflect.Type]int = map[reflect.Type]int{ reflect.TypeOf(DataMessage{}): 1000, reflect.TypeOf(TextMessage{}): 1001, //.... } func GetMessageTypeId(value interface{}) int { if id, ok := dict[reflect.TypeOf(value)]; ok { return id } else { return -1 } } func GetValueByTypeId(typeId int) interface{} { for