Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
Add debug requests mode
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ksio committed Oct 7, 2021
1 parent b46aef2 commit 437c084
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/flow-rosetta-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/rs/zerolog"
"github.com/spf13/pflag"
"github.com/ziflex/lecho/v2"
Expand Down Expand Up @@ -70,6 +71,7 @@ func run() int {
flagTransactions uint
flagSmart bool
flagWait bool
flagDump bool
)

pflag.StringVarP(&flagDPS, "dps-api", "a", "127.0.0.1:5005", "host address for GRPC API endpoint")
Expand All @@ -79,6 +81,7 @@ func run() int {
pflag.Uint16VarP(&flagPort, "port", "p", 8080, "port to host Rosetta API on")
pflag.UintVarP(&flagTransactions, "transaction-limit", "t", 200, "maximum amount of transactions to include in a block response")
pflag.BoolVar(&flagSmart, "smart-status-codes", false, "enable smart non-500 HTTP status codes for Rosetta API errors")
pflag.BoolVar(&flagDump, "dump-requests", false, "print out full request and responses")
pflag.BoolVarP(&flagWait, "wait-for-index", "w", false, "wait for index to be available instead of quitting right away, useful when DPS Live index bootstraps")

pflag.Parse()
Expand Down Expand Up @@ -176,7 +179,22 @@ wait:
server.HideBanner = true
server.HidePort = true
server.Logger = elog
server.Use(lecho.Middleware(lecho.Config{Logger: elog}))

logger := lecho.Middleware(lecho.Config{Logger: elog})

if flagDump {
logger = middleware.BodyDump(func(c echo.Context, request []byte, response []byte) {
fmt.Printf("<<<< %s %s\n%s>>>> %d\n%s\n",
c.Request().Method,
c.Request().RequestURI,
string(request),
c.Response().Status,
string(response),
)
})
}

server.Use(logger)

// This group contains all of the Rosetta Data API endpoints.
server.POST("/network/list", dataCtrl.Networks)
Expand Down

0 comments on commit 437c084

Please sign in to comment.