From c02dc41938e832d51f65c907008029a3ae4c37c3 Mon Sep 17 00:00:00 2001 From: Abdulsamad Sheikh <abdulsas@stud.ntnu.no> Date: Thu, 7 Mar 2024 07:16:55 +0000 Subject: [PATCH] Update services.go --- services/services.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/services.go b/services/services.go index d0ebd0c..00a8476 100644 --- a/services/services.go +++ b/services/services.go @@ -75,16 +75,19 @@ func CalculateUniqueAuthors(books []models.GutenbergBook) int { return len(authorsSet) } -// CheckServiceAvailability checks the availability of a given service URL. -func CheckServiceAvailability(serviceURL string) string { +func CheckServiceAvailability(serviceURL string) int { resp, err := http.Get(serviceURL) if err != nil { - return "Unavailable" + // If there's an error, might want to return a status code indicating the service is unavailable + return http.StatusServiceUnavailable } defer resp.Body.Close() - return http.StatusText(resp.StatusCode) + + // Return the HTTP status code of the response + return resp.StatusCode } + // Assuming you have a global variable to track the start time of your service. var serviceStartTime = time.Now() -- GitLab