The Go standard library includes powerful, often overlooked packages like archive/tar, bytes, and runtime/metrics that handle complex tasks without external dependencies. Use archive/tar for creating archives, bytes for efficient byte slice manipulation, and runtime/metrics for observing runtime behavior via counters like /godebug/non-default-behavior/<name>:events.
import (
"archive/tar"
"bytes"
"runtime/metrics"
)
// Create a tar archive
var buf bytes.Buffer
w := tar.NewWriter(&buf)
w.WriteHeader(&tar.Header{Name: "file.txt", Size: 5})
w.Write([]byte("hello"))
w.Close()
// Read runtime metrics
ms := []metrics.Sample{{Name: "/godebug/non-default-behavior/http2client:events"}}
metrics.Read(ms)
fmt.Println(ms[0].Value.Uint64())