kata

module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0

README

kata

The shared foundation for MizuchiLabs tools. Standard library only, zero dependencies.

Package Purpose
buildinfo Version/commit/date via ldflags, with debug.ReadBuildInfo() fallback so go install builds report real versions
logx Standard slog setup: text on a terminal, JSON when piped, always stderr
sigx signal.NotifyContext with force-quit on second signal

Install

go get github.com/mizuchilabs/kata@latest

Usage

import (
	"context"
	"fmt"
	"log/slog"
	"os"

	"github.com/mizuchilabs/kata/buildinfo"
	"github.com/mizuchilabs/kata/logx"
	"github.com/mizuchilabs/kata/sigx"
	"github.com/urfave/cli/v3"
)

func main() {
	cmd := &cli.Command{
		Name:    "myapp",
		Version: buildinfo.String(),
		Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
			logx.Init(cmd.Bool("debug"))
			return ctx, nil
		},
		Action: func(ctx context.Context, cmd *cli.Command) error {
			slog.Info("running")
			return nil
		},
		Flags: []cli.Flag{
			&cli.BoolFlag{
                Name: "debug",
                Usage: "enable debug logging",
            },
		},
	}

	if err := cmd.Run(sigx.NotifyContext(), os.Args); err != nil {
		fmt.Fprintf(os.Stderr, "myapp: %v\n", err)
		os.Exit(1)
	}
}

buildinfo.UserAgent(name) returns name/version (goos/arch) for HTTP clients.

logx redacts credentials (password, token, authorization, and so on) from every attribute, including nested groups. Register project-specific keys before calling logx.Init:

logx.AddSensitiveKeys("dsn", "client_secret")
logx.Init(cmd.Bool("debug"))

goreleaser

ldflags:
  - -s -w
  - -X github.com/mizuchilabs/kata/buildinfo.Version={{ .Version }}
  - -X github.com/mizuchilabs/kata/buildinfo.Commit={{ .Commit }}
  - -X github.com/mizuchilabs/kata/buildinfo.Date={{ .CommitDate }}

Without ldflags, values fall back to VCS info stamped by the Go toolchain, so binaries installed via go install still report their tag, commit, and date.

Directories

Path Synopsis
Package buildinfo exposes version metadata for MizuchiLabs tools.
Package buildinfo exposes version metadata for MizuchiLabs tools.
Package logx installs the standard slog configuration: human-readable text on a terminal, JSON when piped or running under a service manager, always on stderr.
Package logx installs the standard slog configuration: human-readable text on a terminal, JSON when piped or running under a service manager, always on stderr.
Package sigx provides graceful-shutdown signal handling.
Package sigx provides graceful-shutdown signal handling.

Jump to

Keyboard shortcuts

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