I am trying to write a function which can be used by different structs. The return of the function has to be a slice of the corresponding struct. Thus I need a function which accept a struct as a parameter and return a slice. My code somehow looks like this but I have no idea how can I wrap it as a function?
type name struct{
FirstName string `xml:"firstName"`
LastName string `xml:"lastName"`
}
fileList := TreeTraversal(".")
var a name
var b []name
for i := 0; i < len(fileList); i++{
fileByte, _ := ioutil.ReadFile(fileList[i])
xml.Unmarshal(fileByte, &a)
b = append(b, a)
}
As far as I know I can pass a struct to a function as an interface, but I have no idea about the return type?