I am having some trouble handling data received by my websocket server written in Go using gorilla.
I am communicating in JSON, where there is a action_type to every JSON object, but rest of the content is unknown at run time. I currently use conn.ReadJSON(&message)
where message := make(map[string]interface{})
. The problem is when the JSON looks like this:
{
"action_type": "test",
"something": {
"one": 1,
"two": "two",
},
}
How would I go about parsing "something" in to Go variable with defined Go struct:
type Something struct {
one int
two string
}
s := data["something"].(Something)
is not working, returning error: interface conversion: interface {} is map[string]interface {}, not Something.