go-utils

module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: MIT

README

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

Directories

Path Synopsis
Package blocksub implements an Ethereum block subscriber that works with polling and/or websockets.
Package blocksub implements an Ethereum block subscriber that works with polling and/or websockets.
Package cli implements various reusable utility functions for command-line interfaces.
Package cli implements various reusable utility functions for command-line interfaces.
Package envflag is a wrapper for stdlib's flag that adds the environment variables as additional source of the values for flags.
Package envflag is a wrapper for stdlib's flag that adds the environment variables as additional source of the values for flags.
examples
blocksub
Example for multiple subscribers
Example for multiple subscribers
Package httplogger implements a middleware that logs the incoming HTTP request & its duration using go-ethereum-log or logrus
Package httplogger implements a middleware that logs the incoming HTTP request & its duration using go-ethereum-log or logrus
Package jsonrpc is a minimal JSON-RPC implementation
Package jsonrpc is a minimal JSON-RPC implementation
Package logutils implements helpers for logging.
Package logutils implements helpers for logging.
Package truthy implements helpers to test the truthy-ness of the values.
Package truthy implements helpers to test the truthy-ness of the values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL