add additional healthcheck route
This commit is contained in:
parent
ca5a726e75
commit
dfc2a06257
26
server.go
26
server.go
@ -1,6 +1,7 @@
|
|||||||
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "net/http"
|
import "net/http"
|
||||||
import "os"
|
import "os"
|
||||||
@ -15,6 +16,23 @@ func serve() {
|
|||||||
s.ListenAndServe()
|
s.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getHealthCheckHandler() http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
result := gin.H{
|
||||||
|
"status": "ok",
|
||||||
|
"now": time.Now().UTC().Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
json, err := json.Marshal(result)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(json)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getRouter() *gin.Engine {
|
func getRouter() *gin.Engine {
|
||||||
|
|
||||||
if os.Getenv("DEBUG") == "" {
|
if os.Getenv("DEBUG") == "" {
|
||||||
@ -30,12 +48,8 @@ func getRouter() *gin.Engine {
|
|||||||
// attach logger middleware
|
// attach logger middleware
|
||||||
r.Use(ginzerolog.Logger("gin"))
|
r.Use(ginzerolog.Logger("gin"))
|
||||||
|
|
||||||
r.GET("/.well-known/healthcheck.json", func(c *gin.Context) {
|
r.GET("/.well-known/healthcheck.json", gin.WrapF(getHealthCheckHandler()))
|
||||||
c.JSON(200, gin.H{
|
r.GET("/admin/healthcheck.json", gin.WrapF(getHealthCheckHandler()))
|
||||||
"status": "ok",
|
|
||||||
"now": time.Now().UTC().Format(time.RFC3339),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// call it, it returns the appropriate handler function
|
// call it, it returns the appropriate handler function
|
||||||
// so we can execute some code at startup time
|
// so we can execute some code at startup time
|
||||||
|
Loading…
Reference in New Issue
Block a user