go-snk
Type-safe generic helpers for slices, maps, strings, errors, JSON, HTTP, and containers, organized as small independently adoptable packages
About go-snk
go-snk — the kitchen sink for clean Go projects
go-snk is the library you pull into any Go project to clean it up and keep it clean. The name is short for
kitchen sink — not because it does everything, but because it collects the small, type-safe helpers you keep reaching
for across projects. No repeated loops, no one-off helpers scattered through your codebase, just consistent patterns
for the things you do all the time.
Getting Started
Installation
go get github.com/SharkByteSoftware/go-snk@latest
Import only the packages you need:
package main
import (
"github.com/SharkByteSoftware/go-snk/slicex"
"github.com/SharkByteSoftware/go-snk/slicex/parallel"
)
Quick example
type Order struct {
ID string
Customer string
Shipped bool
}
pending := slicex.Filter(orders, func(o Order) bool { return !o.Shipped })
ids := slicex.Map(pending, func(o Order) string { return o.ID })
byCustomer := slicex.GroupBy(pending, func(o Order) string { return o.Customer })
Three lines instead of three hand-rolled loops, with each step's intent explicit.
Bounded parallelism, results in order
// Look up every shipment with at most 16 requests in flight.
// statuses[i] always matches shipmentIDs[i].
statuses := parallel.MapWithLimit(shipmentIDs, func(id string) Status {
return tracker.Lookup(ctx, id)
}, 16)
statuses := make([]Status, len(shipmentIDs))
sem := make(chan struct{}, 16)
var wg sync.WaitGroup
for i, id := range shipmentIDs {
wg.Add(1)
sem <- struct{}{}
go func() {
defer wg.Done()
defer func() { <-sem }()
statuses[i] = tracker.Lookup(ctx, id)
}()
}
wg.Wait()
A panic inside the callback is re-raised on the caller's goroutine, so recover works just as it does with the sequential slicex functions.
Why go-snk?
Stdlib first: go-snk fills the gaps slices/maps leave out (Map, Filter, GroupBy…)
with consistent S ~[]T / M ~map[K]V constraints, order-preserving, bounded-concurrency parallel variants,
and backend helpers (jsonx, httpx, httpxtest).
Compared with samber/lo, it's narrower and more opinionated. → Full comparison
Documentation
| Package | Description | Docs |
|---|---|---|
slicex | Helpers for filtering, mapping, searching, grouping, zipping, windowing, rotating, and numeric operations on slices | slicex.md |
slicex/parallel | Parallel slice helpers for independent per-item work | slicex.md |
mapx | Helpers for common map operations including partitioning, key mapping, counting by classifier, and merging maps | mapx.md |
httpx | Lightweight helpers for HTTP requests with less boilerplate | httpx.md |
httpxtest | Builder for httptest servers with canned responses, per-route handlers, and response shaping | httpxtest.md |
jsonx | Helpers for encoding and decoding JSON to and from readers, byte slices, and strings | jsonx.md |
conditional | Concise helpers for branching and value selection | conditional.md |
stringx | Helpers for blank checks, fallback selection, truncation, wrapping, and padding strings | stringx.md |
errorx | Helpers for intentional error suppression, initialization panics, multi-target error checks, and reducing multiple errors to one | errorx.md |
containers | Reusable data structures including lists, sets, stacks, queues, and priority queues | README.md |
helpers | Generic utilities for pointer handling and zero value operations | helpers.md |
For a full overview of the library, see docs/overview.md.
License
MIT License, see LICENSE for details
Frequently Asked Questions
What is go-snk?
go-snk is a Utilities library for the Go programming language. Type-safe generic helpers for slices, maps, strings, errors, JSON, HTTP, and containers, organized as small independently adoptable packages
How do I install go-snk?
Install go-snk with the Go module system using `go get SharkByteSoftware/go-snk`. Check the repository for the current installation instructions.
What category does go-snk belong to?
go-snk is listed under Utilities, specifically Utilities.