https://github.com/flashbots/go-utils
Reusable Go utilities and modules
https://github.com/flashbots/go-utils
Last synced: about 1 year ago
JSON representation
Reusable Go utilities and modules
- Host: GitHub
- URL: https://github.com/flashbots/go-utils
- Owner: flashbots
- License: mit
- Created: 2022-02-16T18:51:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-02T12:21:31.000Z (about 1 year ago)
- Last Synced: 2025-04-12T21:08:31.479Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 120 KB
- Stars: 17
- Watchers: 13
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-utils
[](https://github.com/flashbots/go-utils/actions?query=workflow%3A%22Checks%22)
Various reusable Go utilities and modules
## `cli`
Various minor command-line interface helpers: [`cli.go`](https://github.com/flashbots/go-utils/blob/main/cli/cli.go)
## `httplogger`
Logging middleware for HTTP requests using [`go-ethereum/log`](https://github.com/ethereum/go-ethereum/tree/master/log).
See [`examples/httplogger/main.go`](https://github.com/flashbots/goutils/blob/main/examples/httplogger/main.go)
Install:
```bash
go get github.com/flashbots/go-utils/httplogger
```
Use:
```go
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`](https://github.com/flashbots/goutils/blob/main/examples/blocksub/main.go) and [`examples/blocksub/multisub.go`](https://github.com/flashbots/goutils/blob/main/examples/blocksub/multisub.go)
Install:
```bash
go get github.com/flashbots/go-utils/blocksub
```
Use:
```go
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())
}
```