Add healthcheck endpoints and scripts
This commit is contained in:
@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
port, exists := os.LookupEnv("PORT")
|
||||
if !exists {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
client := http.Client{
|
||||
Timeout: 2 * time.Second,
|
||||
}
|
||||
|
||||
resp, err := client.Get("http://localhost:" + port + "/ping")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Print the HTTP Status Code and Status Name
|
||||
fmt.Println("HTTP Response Status:", resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
|
||||
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
|
||||
fmt.Println("HTTP Status is in the 2xx range")
|
||||
} else {
|
||||
fmt.Println("Argh! Broken")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@ -42,5 +42,11 @@ func main() {
|
||||
"now": tm,
|
||||
})
|
||||
})
|
||||
r.Run() // listen and serve on 0.0.0.0:8080
|
||||
|
||||
r.GET("/ping", func(c *gin.Context) {
|
||||
tm = database.GetTime(c)
|
||||
c.JSON(200, "pong")
|
||||
})
|
||||
|
||||
r.Run() // listen and serve on 0.0.0.0:8080 (or "PORT" env var)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user