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

Editetd http requests

parent 8c9886ab
No related branches found
No related tags found
No related merge requests found
......@@ -109,14 +109,42 @@ func ReadershipHandler(w http.ResponseWriter, r *http.Request) {
}
func StatusHandler(w http.ResponseWriter, r *http.Request) {
status := models.ServiceStatus{
GutendexAPI: services.CheckServiceAvailability("http://129.241.150.113:8000/books/"),
LanguageAPI: services.CheckServiceAvailability("http://129.241.150.113:3000/language2countries/"),
CountriesAPI: services.CheckServiceAvailability("http://129.241.150.113:8080/v3.1/"),
// Initialize a variable to track the start time of the service if not already done
// This should ideally be done at the application start, not here
// Assuming services.ServiceStartTime is the time when your service started
// Define the URLs for the services to check
gutendexURL := "http://129.241.150.113:8000/books/"
languageURL := "http://129.241.150.113:3000/language2countries/"
countriesURL := "http://129.241.150.113:8080/v3.1/"
// Use the CheckServiceAvailability function to get the status codes
gutendexStatus := services.CheckServiceAvailability(gutendexURL)
languageStatus := services.CheckServiceAvailability(languageURL)
countriesStatus := services.CheckServiceAvailability(countriesURL)
// Calculate uptime
uptime := int64(time.Since(services.ServiceStartTime).Seconds())
// Create a response struct
statusResponse := struct {
GutendexAPI int `json:"gutendexapi"`
LanguageAPI int `json:"languageapi"`
CountriesAPI int `json:"countriesapi"`
Version string `json:"version"`
Uptime int64 `json:"uptime"`
}{
GutendexAPI: gutendexStatus,
LanguageAPI: languageStatus,
CountriesAPI: countriesStatus,
Version: "v1",
Uptime: services.GetUptime(), // Implement GetUptime in services package
Uptime: uptime,
}
// Set the header and encode the response as JSON
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(status)
if err := json.NewEncoder(w).Encode(statusResponse); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment