I have a simple task.
- Array of people object comes in, up to a thousand.
- Need to iterate over it, and create a custom payload for external service.
I have created a working solution, but I would like to see if I am totally off course, and what changes should I make.
I have reduced non-important details from the code (errors, and similar), so it might not work. But the point is to show how it works, and hopefully get some advice.
User struct {
Name string `json:"name"`
Lastname string `json:"lastname"`
}
func HandleLambda(event events.SQSEvent) {
var userRecords []map[string]interface{}
for idx := range event.Records {
record := event.Records[idx]
ev, err := e.NewEvent(record.Body)
if err != nil {
continue
}
u, err := repository.NewUser(ev)
if err != nil {
continue
}
user := make(map[string]interface{})
user["1"] = u.Name
user["2"] = u.Lastname
userRecords = append(userRecords, user)
}
uJSON, _ := json.Marshal(userRecords)
// I send this to external service
}
External service is using numbers as keys, that's why I need "1" and "2". I do not have control over it. That's the way it works.