I have a function below, and I would like to make it generic:
func genericUnmarshalForType1(file string) Type1 {
raw, err := ioutil.ReadFile(file)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
var type1 Type1
json.Unmarshal(raw, &type1)
}
I would like to create a function that accepts Type1 or Type2 without the need to create a function per type. How can I do this?