project: init

This commit is contained in:
2021-12-14 14:24:18 +03:00
commit a543115d40
7 changed files with 402 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
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,
})
}

17
internal/server/router.go Normal file
View File

@@ -0,0 +1,17 @@
package server
import (
"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)
}