goutils

package module
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0, BSD-2-Clause Imports: 0 Imported by: 0

README

GOUTILS

This is a collection of small utility code I've written in Go; the cmd/ directory has a number of command-line utilities. Rather than keep all of these in superfluous repositories of their own or rewriting them for each project, I'm putting them here.

The project can be built with the standard Go tooling.

Contents:

ahash/          Provides hashes from string algorithm specifiers.
assert/         Error handling, assertion-style.
backoff/        Implementation of an intelligent backoff strategy.
cache/          Implementations of various caches.
    lru/        Least-recently-used cache.
    mru/        Most-recently-used cache.
certlib/        Library for working with TLS certificates.
cmd/
    atping/     Automated TCP ping, meant for putting in cronjobs.
    ca-signed/  Validate whether a certificate is signed by a CA.
    cert-bundler/
                Create certificate bundles from a source of PEM
                certificates.
    cert-revcheck/
                Check whether a certificate has been revoked or is
                expired.
    certchain/  Display the certificate chain from a TLS connection.
    certdump/   Dump certificate information.
    certexpiry/ Print a list of certificate subjects and expiry times
                or warn about certificates expiring within a certain
                window.
    certverify/ Verify a TLS X.509 certificate file, optionally printing
                the time to expiry and checking for revocations.
    clustersh/  Run commands or transfer files across multiple
                servers via SSH.
    cruntar/    (Un)tar an archive with hard links, copying instead of
                linking.
    csrpubdump/ Dump the public key from an X.509 certificate request.
    data_sync/  Sync the user's homedir to external storage.
    diskimg/    Write a disk image to a device.
    dumpbytes/  Dump the contents of a file as hex bytes, printing it as
                a Go []byte literal.
    eig/        EEPROM image generator.
    fragment/   Print a fragment of a file.
    host/       Go imlpementation of the host(1) command.
    jlp/        JSON linter/prettifier.
    kgz/        Custom gzip compressor / decompressor that handles 99%
                of my use cases.
    minmax/     Generate a minmax code for use in uLisp.
    parts/      Simple parts database management for my collection of
                electronic components.
    pem2bin/    Dump the binary body of a PEM-encoded block.
    pembody/    Print the body of a PEM certificate.
    pemit/      Dump data to a PEM file.
    readchain/  Print the common name for the certificates
                in a bundle.
    renfnv/     Rename a file to base32-encoded 64-bit FNV-1a hash.
    rhash/      Compute the digest of remote files.
    rolldie/    Roll some dice.
    showimp/    List the external (e.g. non-stdlib and outside the
                current working directory) imports for a Go file.
    ski         Display the SKI for PEM-encoded TLS material.
    sprox/      Simple TCP proxy.
    stealchain/ Dump the verified chain from a TLS connection to a
                server.
    stealchain-server/
                Dump the verified chain from a TLS connection from
                from a client.
    subjhash/   Print or match subject info from a certificate.
    tlsinfo/    Print information about a TLS connection (the TLS version
                and cipher suite).
    tlskeypair/ Check whether a TLS certificate and key file match.
    utc/        Convert times to UTC.
    yamll/      A small YAML linter.
    zsearch/    Search for a string in directory of gzipped files.
config/         A simple global configuration system where configuration
                data is pulled from a file or an environment variable
                transparently.
    iniconf/    A simple INI-style configuration system.
dbg/            A debug printer.
die/            Death of a program.
fileutil/       Common file functions.
lib/            Commonly-useful functions for writing Go programs.
log/            A syslog library.
logging/        A logging library.
msg/            Output library for command line programs.
mwc/            MultiwriteCloser implementation.
sbuf/           A byte buffer that can be wiped.
seekbuf/        A read-seekable byte buffer.
syslog/         Syslog-type logging.
tee/            Emulate tee(1)'s functionality in io.Writers.
testio/         Various I/O utilities useful during testing.
twofactor/      Two-factor authentication.

Each program should have a small README in the directory with more information.

All code here is licensed under the Apache 2.0 license.

Error handling

This repo standardizes on Go 1.13+ error wrapping and matching. Libraries and CLIs should:

  • Wrap causes with context using fmt.Errorf("context: %w", err).
  • Use typed, structured errors from certlib/certerr for certificate-related operations. These include a typed *certerr.Error with Source and Kind.
  • Match errors programmatically:
    • errors.Is(err, certerr.ErrEncryptedPrivateKey) to detect sentinel states.
    • errors.As(err, &e) (where var e *certerr.Error) to inspect e.Source/e.Kind.

Examples:

cert, err := certlib.LoadCertificate(path)
if err != nil {
    // sentinel match:
    if errors.Is(err, certerr.ErrEmptyCertificate) {
        // handle empty input
    }

    // typed error match
    var ce *certerr.Error
    if errors.As(err, &ce) {
        switch ce.Kind {
        case certerr.KindParse:
            // parse error handling
        case certerr.KindLoad:
            // file loading error handling
        }
    }
}

Documentation

Overview

Package goutils is a top-level package containing a number of utility libraries and command-line programs.

Directories

Path Synopsis
Package ahash provides support for hashing data with a selectable
Package ahash provides support for hashing data with a selectable
Package assert provides C-like assertions for Go.
Package assert provides C-like assertions for Go.
Package backoff contains an implementation of an intelligent backoff strategy.
Package backoff contains an implementation of an intelligent backoff strategy.
cache
lru
Package lru implements a Least Recently Used cache.
Package lru implements a Least Recently Used cache.
mru
certerr
Package certerr provides typed errors and helpers for certificate-related operations across the repository.
Package certerr provides typed errors and helpers for certificate-related operations across the repository.
dump
Package dump implements tooling for dumping certificate information.
Package dump implements tooling for dumping certificate information.
hosts
Package hosts provides a simple way to parse hostnames and ports.
Package hosts provides a simple way to parse hostnames and ports.
revoke
Package revoke provides functionality for checking the validity of a cert.
Package revoke provides functionality for checking the validity of a cert.
ski
cmd
atping command
bcuz command
ca-signed command
cert-bundler command
cert-revcheck command
certchain command
certdump command
certexpiry command
certser command
certverify command
clustersh command
cruntar command
csrpubdump command
data_sync command
diskimg command
dumpbytes command
eig command
fragment command
host command
jlp command
kgz command
minmax command
parts command
pem2bin command
pembody command
pemit command
readchain command
renfnv command
rhash command
rolldie command
showimp command
showimp is a utility for displaying the imports in a package.
showimp is a utility for displaying the imports in a package.
ski command
sprox command
stealchain command
subjhash command
tlsinfo command
tlskeypair command
utc command
yamll command
zsearch command
zsearch is a utility for searching zlib-compressed files for a search string.
zsearch is a utility for searching zlib-compressed files for a search string.
Package config implements a simple global configuration system that supports a file with key=value pairs and environment variables.
Package config implements a simple global configuration system that supports a file with key=value pairs and environment variables.
Package dbg implements a simple debug printer.
Package dbg implements a simple debug printer.
Package die contains utilities for fatal error handling.
Package die contains utilities for fatal error handling.
Package fileutil contains common file functions.
Package fileutil contains common file functions.
lib
dialer
Package dialer provides proxy-aware dialers for plain TCP and TLS connections using environment variables.
Package dialer provides proxy-aware dialers for plain TCP and TLS connections using environment variables.
Package log is a syslog-type facility for logging.
Package log is a syslog-type facility for logging.
Package logging implements attribute-based logging.
Package logging implements attribute-based logging.
example command
Package msg is a tool for handling commandline output based on flags for quiet, verbose, and debug modes.
Package msg is a tool for handling commandline output based on flags for quiet, verbose, and debug modes.
Package mwc implements MultiWriteClosers.
Package mwc implements MultiWriteClosers.
Package sbuf implements a byte buffer that can be wiped.
Package sbuf implements a byte buffer that can be wiped.
Package seekbuf implements a read-seekable buffer.
Package seekbuf implements a read-seekable buffer.
Package testio implements various io utility types.
Package testio implements various io utility types.
Package twofactor implements two-factor authentication.
Package twofactor implements two-factor authentication.

Jump to

Keyboard shortcuts

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