I have a function that looks like this:
func Foo(result interface{}) error {
...
json.Unmarshal([]byte(some_string), result)
...
}
Which is called like this:
var bar Bar
Foo(&bar)
Generally, Foo fetches a string that is then unmarshalled into the result. However, now I need to update it so that Foo sometimes loads data from another source and returns that instead.
type Loader func() (interface{})
func Foo(result interface{}, Loader load) error {
...
data := load()
// result = data ???
...
}
Is there any way for me to assign this new value to result? I found that I can marshal the data into a string and then unmarshal it into result which works, but I can't imagine that's the best way.