I am writing mapping functions that map my internal models to those that I will expose in my API.
How do I map the Locations property. Do I range over them? Do I have to init the UserApi locations first?
I little confused on how to best do this without having any nil exceptions etc.
func mapUserToApi(user User) UserApi {
api := &UserApi{
Id: user.Id,
..
..
}
for index, location := range user.Locations {
/// ????????????
}
return api
}
func mapLocationToApi(location Locatio) LocationApi {
..
}
type User struct {
Id int
Locations []Location
}
type UserApi struct {
Id int
Locations []LocationApi
}