How to make array of struct and return from a function in golang?
Use append to collect the results in a slice.
func procData(values []string) ([]Process, error) {
var result []Process
for _, value := range values {
var process Process
pieces := strings.Split(value, "-")
if len(pieces) > 1 {
process = Process{pieces[0], pieces[1]}
} else if len(pieces) > 2 {
process = Process{pieces[0], pieces[2]}
}
result = append(result, process)
}
return result
}