Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
assignment1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Abdulsamad Sheikh
assignment1
Commits
ec70f46f
Commit
ec70f46f
authored
1 year ago
by
Abdulsamad Sheikh
Browse files
Options
Downloads
Patches
Plain Diff
Editetd http requests
parent
8c9886ab
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
handlers/handlers.go
+35
-7
35 additions, 7 deletions
handlers/handlers.go
with
35 additions
and
7 deletions
handlers/handlers.go
+
35
−
7
View file @
ec70f46f
...
@@ -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
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment