go-kt

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: GPL-3.0

README

go-kt

GitHub release Go Version License build test lint coverage

The small packages every katbyte command-line tool needs, kept in one place instead of copy-pasted into each repo.

package what it is for
clog the shared logrus logger: stderr, timestamps, level from the tool's own env var
cout verbosity-levelled, coloured console output (--quiet, --verbose, --silent)
chttp an http.Client with trace logging, per-attempt timeouts, and retries that never re-send a mutation whose fate is unknown
version the tool's version, stamped at build time or taken from module build info
pointer From and To for optional API fields: dereference-or-zero, and pointer-to-value in expression position

Usage

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

func init() {
    clog.SetLevelFromEnv("MYTOOL_LOG") // "debug", "trace", ... default WARN
}

func run(silent, quiet, verbose bool) {
    cout.SetLevelFromFlags(silent, quiet, verbose) // or embed cout.Flags in your flag struct and call Apply()

    cout.Printf("<green>mytool</> %s\n", version.Version)
    cout.Verbosef("only with -v\n")
    cout.Quietf("%s\n", "the one line a script parses; printed in quiet mode and above")
    cout.Errorf("<red>error:</> %v\n", err) // stderr, every mode except silent

    client := chttp.NewHTTPClient("MyAPI") // logs every exchange at TRACE, retries 429/5xx
    req = chttp.MarkRetrySafe(req)         // a POST that is really a read may be retried on 5xx too
}
Stamping the version

Point the linker at this module's variables instead of a local lib/version:

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

Tools installed with go install ...@version report the module version from build info; plain local builds report dev.

Development

make tools      # build the pinned dev tools into .tools/bin
make check-all  # build + test + lint + actionlint + yamllint + shellcheck + typos + depscheck
make cover      # tests with coverage; the coverage workflow publishes the total as the README badge

Nothing is vendored (consumers resolve dependencies through go.sum); tool versions are pinned in .tools/go.mod and dependabot keeps both current.

Directories

Path Synopsis
Package chttp provides the HTTP client every katbyte tool talks to APIs with: trace-level request/response logging through clog, per-attempt timeouts so a stalled server fails fast, and retries for transient failures that are careful never to re-send a mutation whose outcome is unknown.
Package chttp provides the HTTP client every katbyte tool talks to APIs with: trace-level request/response logging through clog, per-attempt timeouts so a stalled server fails fast, and retries for transient failures that are careful never to re-send a mutation whose outcome is unknown.
Package clog provides the shared logrus logger used by katbyte's tools.
Package clog provides the shared logrus logger used by katbyte's tools.
Package cout provides verbosity-levelled, coloured console output for command-line tools.
Package cout provides verbosity-levelled, coloured console output for command-line tools.
Package pointer converts between values and pointers in expression position.
Package pointer converts between values and pointers in expression position.
Package version exposes the version of the tool that imports it.
Package version exposes the version of the tool that imports it.

Jump to

Keyboard shortcuts

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