package api import "gitea.24example.ru/spavelit/bpiek/model" var products []model.Product func (a *Api) GetProducts() ([]model.Product, error) { if len(products) > 0 { return products, nil } parentCategoris, err := a.GetParentCategories() if err != nil { return nil, err } for _, category := range parentCategoris { categoriesAndProduct, err := a.GetCategoriesAndProductsBySlugParentCategory(category.Slug) if err != nil { return nil, err } if len(categoriesAndProduct.Products) != 0 { products = append(products, categoriesAndProduct.Products...) } } return products, nil }