I got a map[string]interface{} because decoding to JSON; with normal data, interface most be only a number but in type string, like this :
var a interface{}
a="3"
And then all data will be stored into a struct.
type someStruct struct {
ID string
Number1 int
Number2 int
Number3 int
Number4 int
}
So I need to convert interface to int, but can´t do it easily and efficiently because only the code would be https://play.golang.org/p/oktbvTUbk93, pretty annoying and code does not seem to be readable if you take in mind the fact that I should handle all of possible errors
I would want to convert it directly to int, I´ve been searching for solutions but any of this convertions works as I want https://play.golang.org/p/Dw67U6kZwHC
In case you wondering why I don´t just decode it into struct directly, it´s because it´s dynamic data, the actual decoding occurs like this :
type dataIn struct {
Code int `json:"code"`
ID string `json:"id"`
Data interface{} `json:"data"`
}
And then I handle Data according to code and id, and they all are different data structures, so I can´t directly handle it with JSON