package server import ( "net/http" "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) } func healthHandler(c *gin.Context) { allOk, data := batchHealthCall() if !allOk { // choose a better status code if available c.JSON(http.StatusServiceUnavailable, 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) { allOk, data := batchMetricsCall() if !allOk { // choose a better status code if available c.JSON(http.StatusServiceUnavailable, gin.H{ "message": "could not get node metrics", }) return } c.JSON(http.StatusOK, gin.H{ "gasPrice": data.GasPrice, "blockNumber": data.BlockNumber, "peerCount": data.PeerCount, "pendingTransactionsCount": data.PendingTxCount, "pendingTransactions": data.PendingTx, "enode": data.Enode, }) }