3 ms·
This is actually a rather annoying problem. This is what I'm doing temporarily (all fields have the "omitempty" tag): Fetch struct A from DB Unmarshal
by optymizer 12y ago
This is actually a rather annoying problem. This is what I'm doing temporarily (all fields have the "omitempty" tag):
Fetch struct A from DB
Unmarshal JSON data into &A
Unset read-only fields of A
Save A to DB
It's very inefficient but it beats dealing with bugs caused by various flags not being set (or being unset).
I'll switch to using pointers to boolean, int and string since most other (non-trivial) fields are pointers anyway. I'm not happy about the indirection, but it's certainly much faster than the current database roundtrip I'm performing.
And for anyone shouting 'Rust' - there's always going to be that perfect language out there, at the end of the rainbow.