Sobes.tech
Middle+

Napište funkci errorCount pro spočítání počtu chyb podle služeb (struktura: Service -> Containers -> Logs)

sobes.tech AI

Odpověď od AI

go package main

import "strings"

type Log struct { Message string }

type Container struct { Logs []Log }

type Service struct { Containers []Container }

// errorCount spočítava počet logů s chybami (obsahující "error") ve všech službách func errorCount(services []Service) int { count := 0 for _, service := range services { for _, container := range service.Containers { for _, log := range container.Logs { if strings.Contains(strings.ToLower(log.Message), "error") { count++ } } } } return count }

func main() { // příklad použití }