Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Are you using the json field tags? Adding optional to those tags might help. I'm also a fan of using the easyjson library, I think it makes json a little nicer in go (and quicker since it gets rid of a bunch of reflection code). Another option is ffjson.
-
@azous I’ll give that library a try. The difficulty comes in if you don’t know for certain what kind of data you’ll be getting in advance. The processing then becomes this tedious dance of type checks and case statements.
-
@azous doh- replied to the wrong person.
Shoving them all in an interface doesn’t save much time because you still cant use the data until you’ve typed the fields.
Or at least that’s how it looks from the 50 google searches I did yesterday :P -
hell169546y@Karunamon yep, you were right, without a proper unmarshalling it converts everything to string by default, using the map[string]interface{} type
Related Rants
I really am not a fan of the contortions you have to go through in Golang to deserialize a fucking JSON blob. If this were any other language I would have already had a data structure I could query rather than wasting hours twiddling structs that will be filled properly.
rant
golang
json