Сборка ответа из двух параллельных запросов в хранилище

Код-ревьюMiddle20 минпроверка — Спринт10-t038

Метод Get параллельно (двумя горутинами) запрашивает Storage.Info и Storage.Price и должен склеить результат в список записей. Что здесь не так и как исправить? Обратите внимание на синхронизацию, передачу контекста, обработку ошибок, типы и логику сборки.

Как на собесе: 20 минут, ищи всё — гонки, утечки, ошибки, безопасность, стиль. Ссылайся на строки.

review.gogo
1package demo2 3import (4	"context"5)6 7type Storage interface {8	Info(ids []int) (map[int]*InfoRow, error)9	Price(ctx context.Context, ids []int) (map[int]*PriceRow, error)10}11 12type InfoRow struct {13	ID      int14	Created uint815}16 17type PriceRow struct {18	ID    int19	Value float6420}21 22type Record struct {23	ID    int24	Info  *InfoRow25	Price *PriceRow26}27 28type GetReq struct {29	IDs []int3230}31 32type GetResp struct {33	Records []*Record34}35 36type Server struct {37	storage Storage38}39 40func (s Server) Get(ctx context.Context, req GetReq) (*GetResp, error) {41	var failure error42 43	var infoByID map[int]*InfoRow44	go func() {45		m, e := s.storage.Info(toIntIDs(req.IDs))46		if e != nil {47			failure = e48			return49		}50		infoByID = m51	}()52 53	var priceByID map[int]*PriceRow54	go func() {55		m, e := s.storage.Price(context.Background(), toIntIDs(req.IDs))56		if e != nil {57			failure = e58			return59		}60		priceByID = m61	}()62 63	if failure != nil {64		return nil, failure65	}66 67	out := []*Record{}68	for _, id := range req.IDs {69		if info, ok := infoByID[int(id)]; ok {70			out = append(out, &Record{ID: int(id), Info: info})71		}72 73		if price, ok := priceByID[int(id)]; ok {74			out = append(out, &Record{ID: int(id), Price: price})75		}76	}77 78	return &GetResp{Records: out}, nil79}80 81func toIntIDs(ids []int32) []int {82	// переводит []int32 в []int83	return nil84}
⌘ Enter — проверить