This question already has an answer here:
Given:
type Savable interface {}
type Customer struct {} // satisfies 'Savable'
func GetSaved(id string, s Savable) {
// somehow get a reference to the object from cache
s = cachedObject
// alternately, something like:
// json.Unmarshal(jsonFromDisk, &s)
}
func Foo() {
c := Customer{}
GetSaved("bob", &c)
}
Trying a few configurations, I either get compilation errors related to "Expects *Savable, found *Customer", or the GetSaved
function doesn't actually change what I want to be the 'output variable'. Is this doable, and I'm just not getting the right mix of interface/pointers/etc? Or is this not possible for some reason?
Edit: A working example illustrating the problem.
</div>