> If you cant be sure ahead of time if a value is `"1"` or
> `1` (int or string of int)
...then your data provider is _broken_ and you need to take it up with them :)
Re:Go Is a Shop-Built Jig
by stock_toaster on Thursday September 18, 2014 @01:27AM
(#8333865)
Well, these are B2B customers, who are huge companies. We have actually had customers say they can't even find which servers are running the code, so could we "pretty please with money on top" just make it work anyway....
Sometimes you actually have to deal with what you get, and can't just "fix the other end".
To be fair, a favorite tagline of the Go community is "it solves real problems". Dirty JSON (with no simple way to fix it) is a real problem.
It might be a bit more painful, but it is totally doable. You could parse that field into a generic interface, and check the type in your code, or you could create an interface which requires an `AsInt` method, and implement it for both options.
I personally struggled with the json parsing issue a fair bit, but persevering resulted in me having a mostly static typed setup which has ended up being much better than when I've used JS or Python.
Re:Go Is a Shop-Built Jig
by stock_toaster on Thursday September 18, 2014 @02:44PM
(#8336894)
Yeah. It is indeed possible, just painful. I am thinking of wrapping json or even go-simplejson to add support for attempting to coerce strings to ints, where the target is an int and you happen to get a string(int) via json. Haven't gotten around to it yet though.
For me, the biggest pain point is, to be honest, dealing with json. json in Go is not as fast as you would expect, due to the overhead of runtime reflection. Parsing "loose/dirty" json is also painful. If you cant be sure ahead of time if a value is `"1"` or `1` (int or string of int), and have to support both, you are going to have a bad time.