Перейти к содержимому

Провести ревью кода и затем пофиксить.

go · basicsMerlionне решено

Провести ревью кода и затем пофиксить.

type Storage interface{
Products(products[]string) ([]*Products, error)
Compilations(ctx context.Context, productIds[]string) ([]*Compilations, error)
}
/* domain package */
type Products struct{
Id int
CreatedAt uint8
}
type Compilations struct{
ProductId int
MinPrice float64
MaxPrice float64
}
type ProductWithCompilations struct{
Id CreatedAt
int uint8
Compilations[]*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 error
var products[]*Products
go func() {
result, err:=s.storage.Products(request.Ids)
if err!=nil{
errChan<-err
return
}
products= result
}()
var compilations[]*Compilations
go func() {
result, err:=s.storage.Compilations(context.Background(), request.Ids)
if err!=nil{
errChan<-err
return
}
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 · (код без описания) →