Add healthcheck endpoints and scripts

This commit is contained in:
sid palas
2023-02-05 10:16:47 -05:00
parent af4bca05d0
commit 1ea6754c7f
14 changed files with 241 additions and 20 deletions

View File

@ -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)
}
}

View File

@ -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)
}