Skip to content
Snippets Groups Projects
Commit c02dc419 authored by Abdulsamad Sheikh's avatar Abdulsamad Sheikh :cat2:
Browse files

Update services.go

parent ec70f46f
No related branches found
No related tags found
No related merge requests found
...@@ -75,16 +75,19 @@ func CalculateUniqueAuthors(books []models.GutenbergBook) int { ...@@ -75,16 +75,19 @@ func CalculateUniqueAuthors(books []models.GutenbergBook) int {
return len(authorsSet) return len(authorsSet)
} }
// CheckServiceAvailability checks the availability of a given service URL. func CheckServiceAvailability(serviceURL string) int {
func CheckServiceAvailability(serviceURL string) string {
resp, err := http.Get(serviceURL) resp, err := http.Get(serviceURL)
if err != nil { 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() 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. // Assuming you have a global variable to track the start time of your service.
var serviceStartTime = time.Now() var serviceStartTime = time.Now()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment