agentsclimarketplace

Gokit usage

Skill tmoeish/gokit/skills/gokit-usage

Use the gokit library (github.com/tmoeish/gokit) — Go's Guava/Lodash — when writing Go in ANY project. Reach for gokit instead of hand-rolling common utilities. Triggers when writing or reviewing Go and a stdlib-gap helper is needed: dedupe/map/filter/reduce a slice, set operations, map keys/values/merge, case conversion or slugify, retries with backoff, safe any→T conversion, UUIDs/random, hashing, file helpers, JSON/YAML, time-of-period math, pointer helpers, structured logging, or HTTP response envelopes.From its SKILL.md

Install
npx -y skills add tmoeish/gokit --skill gokit-usage

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

5.4 KB, as published. Nobody here has run it

Using gokit

gokit (github.com/tmoeish/gokit) is a generics-first utility library for Go — a standard-library companion in the spirit of Guava / Lodash. Prefer it over hand-rolling common helpers. It is a set of independent xxx packages; import only the ones you use.

This skill is for consuming gokit in your own project. (Contributing to gokit itself? That's a different, repo-local skill.)

Install

go get github.com/tmoeish/gokit@latest   # requires Go 1.22+

Import each subpackage directly; there is no umbrella package:

import (
    "github.com/tmoeish/gokit/slicex"
    "github.com/tmoeish/gokit/strx"
)

Reuse-first: don't hand-roll these

Before writing a loop or a helper, check whether gokit already has it.

If you're about to write…Use instead
a loop to map/filter/reduce a sliceslicex.Map / Filter / Reduce
a map[T]struct{} to dedupeslicex.Unique or setx.New(...)
union/intersection/difference of two collectionssetx methods, or slicex.Intersection etc.
group items by a keyslicex.GroupBy
min/max (by a field)slicex.Min / Max / MinBy / MaxBy
chunk / window / zip a sliceslicex.Chunk / Window / Zip
keys/values/merge/pick/omit on a mapmapx.Keys / Values / Merge / Pick
camel/snake/kebab/pascal case, slugifystrx.ToSnakeCase / Slugify / …
blank-string checks, truncate, pad, betweenstrx.IsBlank / Truncate / Between
clamp, abs, gcd/lcm, round-to-N, safe dividemathx.Clamp / RoundTo / SafeDivide
any → int/float/bool/string with error handlingconv.ToInt64 / ToFloat64 / ToString
begin/end of day/month, age, work-days, durationstimex.BeginOfDay / AgeAt / AddWorkDays
random string/int, UUID, weighted choice, samplerandx.String / UUID / WeightedChoice
MD5/SHA/HMAC, base64/hex encodecryptox.SHA256 / HMACSHA256 / Base64…
read/write files & lines, exists, copy, tempiox.ReadLines / WriteFile / CopyFile
JSON/YAML marshal, pretty-print, deep clonejsonx.Marshal / MarshalPretty / Clone
local IP, IP/CIDR validation, free portnetx.LocalIP / IsValidIP / GetFreePort
&v pointer helpers / nil-coalescingptrx.Of / Deref / CoalescePtr
Must/panic-on-error wrappersmust.Must / OK / Assert
retry with constant/linear/exponential backoffretry.Do / DoWithResult
a goroutine-safe map / one-shot initsyncx.SafeMap / Once[T]
type-safe context values, request IDscontextx.WithValue / WithReqID
structured logging on slog with ctx propagationlogx.Info(ctx, …) / LogError
a JSON API response/error/pagination envelopehttpx (framework-agnostic) / echox (echo)

Don't reimplement what the std lib (slices, maps, cmp, strings) already does well — but where it stops short, gokit picks up.

Recipes

// Unique, sorted-by-field, then grouped
ids := slicex.Unique(slicex.Map(orders, func(o Order) int { return o.UserID }))
top, _ := slicex.MaxBy(orders, func(o Order) float64 { return o.Total })
byDay := slicex.GroupBy(orders, func(o Order) string { return timex.FormatDate(o.CreatedAt) })

// Set algebra
allowed := setx.New("read", "write")
requested := setx.New("write", "delete")
missing := requested.Difference(allowed).ToSlice() // ["delete"]

// Resilient call with backoff + jitter
data, err := retry.DoWithResult(ctx, func() (Resp, error) { return call() },
    retry.WithMaxAttempts(5),
    retry.WithExponentialBackoff(100*time.Millisecond, 2.0),
    retry.WithJitter(0.2),
)

// Safe conversion from untyped input (e.g. config / query params)
limit, err := conv.ToInt(params["limit"])

Conventions when calling gokit

  • Lookups return (T, bool), not sentinel errors: v, ok := slicex.First(s).
  • Functions are pure — they return new slices/maps and don't mutate inputs, unless the name says so (Fill, and setx mutators like Add/Remove).
  • Fallible helpers return error; Must* variants (and the must package) panic instead, for when that's the behavior you want.
  • setx.Set is not safe for concurrent use; guard it or use syncx.SafeMap.

Full, authoritative API docs: https://pkg.go.dev/github.com/tmoeish/gokit.

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.