https://github.com/xpetit/x
A collection of functions to write concise code.
https://github.com/xpetit/x
generics go golang library
Last synced: 5 months ago
JSON representation
A collection of functions to write concise code.
- Host: GitHub
- URL: https://github.com/xpetit/x
- Owner: xpetit
- License: mit
- Created: 2022-03-28T17:04:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2026-02-20T12:26:26.000Z (5 months ago)
- Last Synced: 2026-02-20T16:40:46.592Z (5 months ago)
- Topics: generics, go, golang, library
- Language: Go
- Homepage: https://pkg.go.dev/github.com/xpetit/x/v5
- Size: 119 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `x`
A collection of functions to write concise code.
```go
sha2 := sha256.New()
src := tar.NewReader(
CloseAfterRead(Must(gzip.NewReader(
io.TeeReader(
CloseAfterRead(Must(http.Get("https://go.dev/dl/go1.20.2.linux-amd64.tar.gz")).Body),
sha2,
),
))),
)
for th, err := src.Next(); err != io.EOF; th, err = src.Next() {
Check(err)
switch th.Typeflag {
case tar.TypeDir:
Check(os.Mkdir(th.Name, 0o755))
case tar.TypeReg:
dst := Must(os.OpenFile(th.Name, os.O_CREATE|os.O_WRONLY, th.FileInfo().Mode()))
Must(io.Copy(dst, src))
Check(dst.Close())
}
}
Assert(hex.EncodeToString(sha2.Sum(nil)) == "4eaea32f59cde4dc635fbc42161031d13e1c780b87097f4b4234cfce671f1768")
```
This snippet downloads an archive, unpacks it and verifies its checksum, all in one go.
Any error causes a panic, cascading errors are stacked and each reader is closed as expected.
---
If you get a warning from `gopls/staticcheck` about dot-import, create a file named `staticcheck.conf` in your project directory (or parents) with:
```
dot_import_whitelist = [ "github.com/xpetit/x/v5" ]
```