/go-utils

Various reusable Go utilities and modules

Primary LanguageGoMIT LicenseMIT

go-utils

Test status

Various reusable Go utilities and modules

cli

Various minor command-line interface helpers: cli.go

httplogger

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)

jsonrpc

Minimal JSON-RPC client implementation.

blocksub

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())
}