openethereum-node-status/internal/server/handlers.go
2021-12-14 14:24:18 +03:00

53 lines
838 B
Go

package server
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
"git.grassecon.org/grassroots-economics/openethereum-node-status/pkg/rpc"
)
type (
R struct {
Result string `json:"result"`
}
P map[string]interface{}
)
var (
RpcClient rpc.RpcClient
)
func metricsHandler(c *gin.Context) {
// pllholder rpc call
rpcResponse, err := RpcClient.EthRpcCall("eth_gasPrice")
if err != nil {
log.Error().
Err(err).
Str("module", "server").
Msg("rpc call failed")
}
value, err := rpcResponse.GetString()
if err != nil {
log.Error().
Err(err).
Str("module", "server").
Msg("rpc response to string conversion failed")
}
c.JSON(http.StatusOK, gin.H{
"ok": true,
"data": value,
})
}
func healthHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"ok": true,
})
}