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) { ...@@ -109,14 +109,42 @@ func ReadershipHandler(w http.ResponseWriter, r *http.Request) {
} }
func StatusHandler(w http.ResponseWriter, r *http.Request) { func StatusHandler(w http.ResponseWriter, r *http.Request) {
status := models.ServiceStatus{ // Initialize a variable to track the start time of the service if not already done
GutendexAPI: services.CheckServiceAvailability("http://129.241.150.113:8000/books/"), // This should ideally be done at the application start, not here
LanguageAPI: services.CheckServiceAvailability("http://129.241.150.113:3000/language2countries/"), // Assuming services.ServiceStartTime is the time when your service started
CountriesAPI: services.CheckServiceAvailability("http://129.241.150.113:8080/v3.1/"),
Version: "v1", // Define the URLs for the services to check
Uptime: services.GetUptime(), // Implement GetUptime in services package 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: uptime,
} }
// Set the header and encode the response as JSON
w.Header().Set("Content-Type", "application/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