Senior
// TODO: implement func (s *Service) GetProducts(ctx context.Context, skus []SKU) (map[SKU]Product, error) { return nil, nil }
sobes.tech AI
Answer from AI
go func (s *Service) GetProducts(ctx context.Context, skus []SKU) (map[SKU]Product, error) { result := make(map[SKU]Product, len(skus))
for _, sku := range skus {
product, err := s.repo.GetProductBySKU(ctx, sku) // assume there is a repository method
if err != nil {
return nil, err
}
result[sku] = product
}
return result, nil
}
It is assumed that the service has access to a repository (`s.repo`) that can fetch a product by SKU. We iterate over the list of SKUs, request each product, and collect them into a map. If an error occurs, we return it immediately.