-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.go
More file actions
51 lines (43 loc) · 1.22 KB
/
ping.go
File metadata and controls
51 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"net/http"
"time"
"github.com/labstack/echo/v4"
)
func ping(c echo.Context) error {
return c.JSON(http.StatusOK, echo.Map{
"message": "pong",
})
}
func ping_mongodb(c echo.Context) error {
primaryChan := make(chan time.Duration)
nearestChan := make(chan time.Duration)
errChan := make(chan error)
go func() {
PrimaryEalapsedTime, PrimaryErr := ping_mongodb_primary()
primaryChan <- PrimaryEalapsedTime
errChan <- PrimaryErr
}()
go func() {
NearestEalapsedTime, NearestErr := ping_mongodb_nearest()
nearestChan <- NearestEalapsedTime
errChan <- NearestErr
}()
PrimaryEalapsedTime := <-primaryChan
NearestEalapsedTime := <-nearestChan
PrimaryErr := <-errChan
NearestErr := <-errChan
if PrimaryErr != nil || NearestErr != nil {
return c.JSON(http.StatusInternalServerError, echo.Map{
"message": "MongoDB is down?",
"PrimaryEalapsedTime": PrimaryEalapsedTime.Milliseconds(),
"NearestEalapsedTime": NearestEalapsedTime.Milliseconds(),
})
} else {
return c.JSON(http.StatusOK, echo.Map{
"message": "MongoDB is up",
"PrimaryEalapsedTime": PrimaryEalapsedTime.Milliseconds(),
"NearestEalapsedTime": NearestEalapsedTime.Milliseconds(),
})
}
}