The Tale of Two Structs
I’ve been using golang for the past few days and I really like it. It’s fast, it’s typesafe, it’s easy to learn and it has concurrency built right into the language.
I have, however, stumbled into a bit of a pickle. file and store the parsed data into a database. It feels like this could simply be accomplished in a single struct with multiple annotations - some for sql some for xml, but I can’t seem to get it to work.
The XML file is quite simple:
And this is my struct that is used by GORM:
Parsing the dates fails, because the date strings in XML are missing the timezone:
I actually managed to solve that by writing my own
functions (see here), but then I couldn’t get GORM to save my custom Time struct.
My current solution is to use
string for date fields and then parse them manually (see below).
I can’t seem to get the rise attr of the sun element without a sun struct in between:
So my current solution is to use two structs and a convert function to convert between the two: