Various reusable Go utilities and modules
Various minor command-line interface helpers: cli.go
Logging middleware for HTTP requests using go-ethereum/log
.
See examples/httplogger/main.go
Install:
go get github.com/flashbots/go-utils/httplogger
Use:
mux := http.NewServeMux()
mux.HandleFunc("/v1/hello", HelloHandler)
loggedRouter := httplogger.LoggingMiddleware(r)
Minimal JSON-RPC client implementation.
Subscribe for new Ethereum block headers by polling and/or websocket subscription
See examples/blocksub/main.go
and examples/blocksub/multisub.go
Install:
go get github.com/flashbots/go-utils/blocksub
Use:
blocksub := blocksub.NewBlockSub(context.Background(), httpURI, wsURI)
if err := blocksub.Start(); err != nil {
panic(err)
}
// Subscribe to new headers
sub := blocksub.Subscribe(context.Background())
for header := range sub.C {
fmt.Println("new header", header.Number.Uint64(), header.Hash().Hex())
}