On Wed, Apr 29, 2020 at 02:17:44PM -0700, MichaelB wrote:
> I'm trying to store a data point as a JSON (w/struct) with a Call back
> function to call when the item is loaded with data
Functions aren't serializeable to json, it's not one of the types json supports.
> Just marshaling the struct into JSON nets a blank item.. any suggestions?
> type Item struct {
> name string
> callback func()
> data int
> }
If you json.Unmarshal into the above struct it can't work.
json is an external package and hence can only work with exported symbols.
You need to capitalize your struct fields in other words.
> after striking out I thought about switching it to a string and doing a
> switch.. but let me know maybe i'm just doing something wrong with the
> callback definition
Yes, enter a string and switch on that.
Greetings,
Reto