Провести ревью кода и затем пофиксить.
Условие
Заголовок раздела «Условие»Провести ревью кода и затем пофиксить.
type Storage interface{Products(products[]string) ([]*Products, error)Compilations(ctx context.Context, productIds[]string) ([]*Compilations, error)}
/* domain package */type Products struct{Id intCreatedAt uint8}
type Compilations struct{ProductId intMinPrice float64MaxPrice float64}
type ProductWithCompilations struct{Id CreatedAtint uint8Compilations[]*Compilations}
/* transport package */type GetRequest struct{Ids[]string}
type GetResponse struct{ProductWithCompilations[]*ProductWithCompilations}
type Server struct{storage Storage}
/* transport package */type GetRequest struct{Ids[]string}
type GetResponse struct{ProductWithCompilations[]*ProductWithCompilations}
type Server struct{storage Storage}
func(s*Server) SearchBywords(ctx context.Context, request*GetRequest) (*GetResponse, error) {var errChan chan errorvar products[]*Productsgo func() {result, err:=s.storage.Products(request.Ids)if err!=nil{errChan<-errreturn}
products= result}()
var compilations[]*Compilationsgo func() {result, err:=s.storage.Compilations(context.Background(), request.Ids)if err!=nil{errChan<-errreturn}comilitations= result}()
for err:=range errChan{if err!=nil{return nil, err}}
result:=[]*ProductWithCompiliation()for _, product:=range products{for _, compilation:=range compilation{if compilation.ProductId==product.id{result= append(result, &ProductWithCompiliation{id: product.Id, createdAt: product.CreatedAt, Complitations: []*Complitations{compiliation}})}}}
return&GetResponse(ProductWithCompilations: result), nil}Решение
Заголовок раздела «Решение»Источник: Merlion
← Смерджить произвольное количество канал… · Все задачи · Go · (код без описания) →