go-kt

module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: GPL-3.0

README

go-kt

GitHub release Go Version License build test lint coverage

The small packages every katbyte tool needs, kept in one place instead of copied into each repo.

package what it is for
clog the shared logger, with its level set from the tool's own environment variable
cout console output with colour and quiet, verbose and silent modes
httpc an HTTP client that retries what is safe to retry and keeps credentials out of logs and errors
httpd the HTTP server under a tool's routes, with a health check and a clean stop
version the tool's version, set at build time
pointer the value behind a pointer, and a pointer to a value
text a description's first sentence or first line, and the article a word takes
spelling tells whether two names are one name spelled two ways
whitespace finds and fixes stray spaces in a name
outside cleans text that came from outside before a model reads it
parallel runs a batch of jobs a few at a time and stops at the first error
lock makes two edits of the same record take turns
mcp/server runs an MCP server over stdio, or over HTTP behind a token
mcp/registry chooses which tools a session gets, logs each write, and keeps credentials out of logs and errors
mcp/acctest tests an MCP server as a client uses it, and fails if a tool was never seen to work
prometheus/metrics a tool's Prometheus metrics page, with a health check
prometheus/poller asks what a tool reports on, on schedules, and keeps the last good answers
prometheus/exporter a tool's print and serve commands, from a poller and a metrics page
prometheus/metricstest checks a tool's metrics page against a saved copy and Prometheus's naming rules
test/replayproxy records what a server under test fetches from the internet, and replays it in CI
test/env sets up a live test's surroundings: its variables, proxy and files
test/services/arrserver stands in for the servers Sonarr, Radarr and Prowlarr call home to
test/services/newznab stand-in Newznab and Torznab indexers that a test controls
test/services/sabnzbd a stand-in SABnzbd that downloads nothing, whose jobs a test controls

The detail for each is on pkg.go.dev.

Install

go get github.com/katbyte/go-kt@latest

It needs Go 1.27 or newer.

Usage

import (
    "github.com/katbyte/go-kt/clog"
    "github.com/katbyte/go-kt/cout"
    "github.com/katbyte/go-kt/httpc"
    "github.com/katbyte/go-kt/version"
)

func init() {
    clog.SetLevelFromEnv("MYTOOL_LOG") // warnings and errors unless the variable says otherwise
}

func run(silent, quiet, verbose bool) {
    cout.SetLevelFromFlags(silent, quiet, verbose)

    cout.Printf("<green>mytool</> %s\n", version.Version)
    cout.Verbosef("only when verbose\n")
    cout.Quietf("still printed when quiet\n")
    cout.Errorf("<red>error:</> %v\n", err) // every mode but silent

    client := httpc.New(httpc.Options{Name: "MyAPI", Log: clog.Log})
    resp, body, err := client.Fetch(req, 16<<20) // the whole answer, up to 16 MB
}
Stamping the version

Point the linker at this module's variables:

# .goreleaser.yaml
ldflags:
  - -X github.com/katbyte/go-kt/version.Version={{ .Tag }}
  - -X github.com/katbyte/go-kt/version.GitCommit={{ .ShortCommit }}

A tool installed with go install reports its module version. A local build reports dev.

Used by

Development

make tools      # install the pinned dev tools
make check-all  # build, test and every lint
make cover      # tests with coverage

Nothing is vendored. Tool versions are pinned in the makefile and .tools/go.mod.

How releases are cut is in CONTRIBUTING.md.

Directories

Path Synopsis
Package clog is the one logger every katbyte tool logs through: stderr, since stdout is the tool's real output, with timestamps, at WARN unless the tool's own variable (TCTEST_LOG, KOI_LOG) raises it.
Package clog is the one logger every katbyte tool logs through: stderr, since stdout is the tool's real output, with timestamps, at WARN unless the tool's own variable (TCTEST_LOG, KOI_LOG) raises it.
Package cout prints for the person running a tool, as clog logs for whoever diagnoses it.
Package cout prints for the person running a tool, as clog logs for whoever diagnoses it.
Package httpc is the HTTP client every katbyte tool talks to APIs with: a stalled server fails fast, a passing failure is tried again without ever re-sending a write whose fate is unknown, and every exchange is traced to whatever logger it is handed, with credentials blanked.
Package httpc is the HTTP client every katbyte tool talks to APIs with: a stalled server fails fast, a passing failure is tried again without ever re-sending a write whose fate is unknown, and every exchange is traced to whatever logger it is handed, with credentials blanked.
Package httpd is the HTTP server under a tool's routes: it listens, answers a health check, and on stop lets requests under way finish.
Package httpd is the HTTP server under a tool's routes: it listens, answers a health check, and on stop lets requests under way finish.
internal
addresses
Package addresses blanks what an address in text may carry a credential in: the one rule behind outside.BlankAddresses and the registry's write line, kept here so the registry can also be told what was blanked.
Package addresses blanks what an address in text may carry a credential in: the one rule behind outside.BlankAddresses and the registry's write line, kept here so the registry can also be told what was blanked.
Package lock makes callers in one process take turns at a record, so one does not undo another's change.
Package lock makes callers in one process take turns at a record, so one does not undo another's change.
mcp
acctest
Package acctest drives an MCP server the way a client does, for a suite against a live one: calls counted for coverage, readers for the answers, waits on background work, put-backs for what a test changed, and a watch on everything the tools say for a key the suite gave the server.
Package acctest drives an MCP server the way a client does, for a suite against a live one: calls counted for coverage, readers for the answers, waits on background work, put-backs for what a test changed, and a watch on everything the tools say for a key the suite gave the server.
registry
Package registry decides which of an MCP server's tools a session gets, what each tells a client about itself, and what stands around every call.
Package registry decides which of an MCP server's tools a session gets, what each tells a client about itself, and what stands around every call.
server
Package server runs an MCP server over stdio for a client that starts it, or over HTTP for an always-on one, behind a bearer token and with a health probe.
Package server runs an MCP server over stdio for a client that starts it, or over HTTP for an always-on one, behind a bearer token and with a health probe.
Package outside makes text from outside safe to hand to a model: a release's name, a file's, anything fetched from a service anyone can write to.
Package outside makes text from outside safe to hand to a model: a release's name, a file's, anything fetched from a service anyone can write to.
Package parallel runs a batch of jobs a few at a time, as many as a server answers at once.
Package parallel runs a batch of jobs a few at a time, as many as a server answers at once.
Package pointer reads and makes the optional fields API models type as *T, where a statement is awkward: inside a literal, an argument or a return.
Package pointer reads and makes the optional fields API models type as *T, where a statement is awkward: inside a literal, an argument or a return.
prometheus
exporter
Package exporter runs a metrics exporter: a poller asking what the tool reports on, and the metrics page written from what it last heard.
Package exporter runs a metrics exporter: a poller asking what the tool reports on, and the metrics page written from what it last heard.
metrics
Package metrics is a tool's Prometheus metrics page: its own readings and nothing else, with the labels whoever runs it wants on every one, written as text or served over HTTP beside a health probe.
Package metrics is a tool's Prometheus metrics page: its own readings and nothing else, with the labels whoever runs it wants on every one, written as text or served over HTTP beside a health probe.
metricstest
Package metricstest is the checks a tool's tests make of its metrics page: that the page is the one saved last time, that its names follow Prometheus's rules, and what a running tool's page says.
Package metricstest is the checks a tool's tests make of its metrics page: that the page is the one saved last time, that its names follow Prometheus's rules, and what a running tool's page says.
poller
Package poller asks what a tool reports on about its state, on schedules of the tool's own, and keeps the last good answer to each question, so a metrics page is written from memory however slow or gone the thing asked is.
Package poller asks what a tool reports on about its state, on schedules of the tool's own, and keeps the last good answer to each question, so a metrics page is written from memory however slow or gone the thing asked is.
Package spelling finds one name spelled two ways, as genres, tags and studios arrive typed by hand: "Sci-Fi" and "sci fi", "Amélie" and "Amelie", "Noir" and "Nior".
Package spelling finds one name spelled two ways, as genres, tags and studios arrive typed by hand: "Sci-Fi" and "sci fi", "Amélie" and "Amelie", "Noir" and "Nior".
test
env
Package env is what a suite against a live server in a container is handed: the variables its test script exports, the replay proxy the server's internet calls go through, a check the container can reach it, the report on what the proxy saw, and files laid out where the container reads them.
Package env is what a suite against a live server in a container is handed: the variables its test script exports, the replay proxy the server's internet calls go through, a check the container can reach it, the report on what the proxy saw, and files laid out where the container reads them.
replayproxy
Package replayproxy records and replays what a server under test fetches from the internet: metadata providers, a podcast feed, an artwork CDN.
Package replayproxy records and replays what a server under test fetches from the internet: metadata providers, a podcast feed, an artwork CDN.
services/arrserver
Package arrserver is the servers a Prowlarr, Sonarr or Radarr calls home to, for a live suite to answer itself: the update server, the clock, and the notices.
Package arrserver is the servers a Prowlarr, Sonarr or Radarr calls home to, for a live suite to answer itself: the update server, the clock, and the notices.
services/newznab
Package newznab is a Newznab and Torznab indexer for a live suite to run beside the server under test: one listener, any number of indexers at /<name>/api, each usenet or torrent, each healthy or broken as the test says.
Package newznab is a Newznab and Torznab indexer for a live suite to run beside the server under test: one listener, any number of indexers at /<name>/api, each usenet or torrent, each healthy or broken as the test says.
services/sabnzbd
Package sabnzbd is a SABnzbd for a live suite to run beside the server under test: a download client that downloads nothing, whose jobs the test moves along itself, written for Sonarr, whose reading of each answer the comments name.
Package sabnzbd is a SABnzbd for a live suite to run beside the server under test: a download client that downloads nothing, whose jobs the test moves along itself, written for Sonarr, whose reading of each answer the comments name.
Package text is small helpers for wording that more than one tool needs: the first sentence of a description, its first line, the article a word takes.
Package text is small helpers for wording that more than one tool needs: the first sentence of a description, its first line, the article a word takes.
Package version is the version of the tool that imports it: stamped at release, else the module version from a go install, else "dev".
Package version is the version of the tool that imports it: stamped at release, else the module version from a go install, else "dev".
Package whitespace finds the spaces out of place in a name: doubled, at an end, odd, or before a colon or a file extension.
Package whitespace finds the spaces out of place in a name: doubled, at an end, odd, or before a colon or a file extension.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL