Store and retrieve interfaces in golang
Store and retrieve interfaces in golang How can we store array of different structs into some file and retrieve it back in the same format without losing its properties(methods it provides). For example: I have data struct A and struct B , both implementing a common interface X {} with some methods. struct A struct B interface X {} One options is to write both save and retrieve method to accept the interface X slice. However the problem is how to unmarshal it back in some generic way which is not tied to my Data struct. i.e., every time I add a new data struct I need not to change my save or retrieve functions to retrieve back the slice of interface X so that its methods can be used independent of data struct. Example where Unmarshaling throws error : Go PlayGround Link with a small Example 3 Answers 3 However the problem is how to unmarshal it back in some generic way which is not tied to my Data...