Skip to content

Commit c300361

Browse files
committed
Modernize code
1 parent aa7b627 commit c300361

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

pkg/http/http.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
12661266
// Retrieve list of ingredients from Catalog.
12671267
var validOliveOils []model.Ingredient
12681268
for _, oliveOil := range oils {
1269-
if !contains(restrictions.ExcludedIngredients, oliveOil.Name) && (!restrictions.MustBeVegetarian || oliveOil.Vegetarian) {
1269+
if !slices.Contains(restrictions.ExcludedIngredients, oliveOil.Name) && (!restrictions.MustBeVegetarian || oliveOil.Vegetarian) {
12701270
validOliveOils = append(validOliveOils, oliveOil)
12711271
}
12721272
}
@@ -1280,7 +1280,7 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
12801280

12811281
var validTomatoes []model.Ingredient
12821282
for _, tomato := range tomatoes {
1283-
if !contains(restrictions.ExcludedIngredients, tomato.Name) && (!restrictions.MustBeVegetarian || tomato.Vegetarian) {
1283+
if !slices.Contains(restrictions.ExcludedIngredients, tomato.Name) && (!restrictions.MustBeVegetarian || tomato.Vegetarian) {
12841284
validTomatoes = append(validTomatoes, tomato)
12851285
}
12861286
}
@@ -1294,7 +1294,7 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
12941294

12951295
var validMozzarellas []model.Ingredient
12961296
for _, mozzarella := range mozzarellas {
1297-
if !contains(restrictions.ExcludedIngredients, mozzarella.Name) && (!restrictions.MustBeVegetarian || mozzarella.Vegetarian) {
1297+
if !slices.Contains(restrictions.ExcludedIngredients, mozzarella.Name) && (!restrictions.MustBeVegetarian || mozzarella.Vegetarian) {
12981298
validMozzarellas = append(validMozzarellas, mozzarella)
12991299
}
13001300
}
@@ -1308,7 +1308,7 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
13081308

13091309
var validToppings []model.Ingredient
13101310
for _, topping := range toppings {
1311-
if !contains(restrictions.ExcludedIngredients, topping.Name) && (!restrictions.MustBeVegetarian || topping.Vegetarian) {
1311+
if !slices.Contains(restrictions.ExcludedIngredients, topping.Name) && (!restrictions.MustBeVegetarian || topping.Vegetarian) {
13121312
validToppings = append(validToppings, topping)
13131313
}
13141314
}
@@ -1322,7 +1322,7 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
13221322

13231323
var validTools []string
13241324
for _, tool := range tools {
1325-
if !contains(restrictions.ExcludedTools, tool) {
1325+
if !slices.Contains(restrictions.ExcludedTools, tool) {
13261326
validTools = append(validTools, tool)
13271327
}
13281328
}
@@ -1351,7 +1351,7 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
13511351

13521352
pizzaCtx, pizzaSpan := tracer.Start(r.Context(), "pizza-generation")
13531353
var p model.Pizza
1354-
for i := 0; i < 10; i++ {
1354+
for range 10 {
13551355
randomName := restrictions.CustomName
13561356

13571357
if randomName == "" {
@@ -1391,7 +1391,7 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
13911391
extraToppings = rand.Intn(extraToppings + 1)
13921392
}
13931393

1394-
for j := 0; j < extraToppings+restrictions.MinNumberOfToppings; j++ {
1394+
for range extraToppings + restrictions.MinNumberOfToppings {
13951395
p.Ingredients = append(p.Ingredients, validToppings[rand.Intn(len(validToppings))])
13961396
}
13971397

@@ -1445,15 +1445,6 @@ func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient Copy
14451445
})
14461446
}
14471447

1448-
func contains(slice []string, value string) bool {
1449-
for _, item := range slice {
1450-
if item == value {
1451-
return true
1452-
}
1453-
}
1454-
return false
1455-
}
1456-
14571448
func FaviconHandler() http.Handler {
14581449
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
14591450
data, _ := web.Static.ReadFile("static/favicon.ico")

0 commit comments

Comments
 (0)