openethereum-node-status/internal/server/router.go

45 lines
774 B
Go
Raw Normal View History

2021-12-14 12:24:18 +01:00
package server
import (
2021-12-14 15:50:07 +01:00
"fmt"
"net/http"
2021-12-14 12:24:18 +01:00
"github.com/gin-gonic/gin"
)
func Start(port string, ginMode string) error {
gin.SetMode(ginMode)
gin.DisableConsoleColor()
router := gin.Default()
router.GET("/metrics", metricsHandler)
router.GET("/health", healthHandler)
return router.Run(port)
}
2021-12-14 15:50:07 +01:00
func healthHandler(c *gin.Context) {
allOk, data := batchCall()
fmt.Println(data.SyncComplete)
if !allOk {
2021-12-14 16:03:47 +01:00
// choose a better status code if available
2021-12-14 15:50:07 +01:00
c.JSON(http.StatusExpectationFailed, gin.H{
"message": "could not get node health status",
})
return
}
c.JSON(http.StatusOK, gin.H{
"syncComplete": data.SyncComplete,
"chainName": data.ChainName,
})
}
func metricsHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"ok": true,
})
}