tools

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

README

tools

set of utility functions

  • PrettyByteSize - returns a human readable string of int bytes

    ${999 => 999 \color{green}\space B}$
    ${2048 => 2.0 \color{green}\space KiB}$
    ${1058575 => 1.01 \color{green}\space MiB}$

packages

logging

slog helpers

  • create logger with default, discard, text or json handler
  • options to set output, loglevel, timeformat, include source, truncate source
config

configuration helper

  • reads yaml config file from XDG_CONFIG_HOME i.e. ~/.config/progname/config into user supplied struct
  • value is cached for quicker subsequent lookups
money

small currency package for handling money

  • supports curreny values up to 100 trillon
  • helper funcs for tax calculations

Documentation

Overview

Package tools implements utility routines

Index

Constants

View Source
const (
	// Escape is ansi terminal escape sequence.
	Escape = "\x1b["
	// Reset is ansi termnial code for reset.
	Reset = Escape + "0m"
	// Green is ansi terminal code for green text.
	Green = Escape + "32m"
)

Variables

View Source
var (
	ErrNotDefined = errors.New("neither $XDG_DATA_HOME nor $HOME are defined") //nolint:revive
	ErrRelative   = errors.New("path in $XDG_DATA_HOME is relative")
)

Functions

func AppConfigDir added in v0.3.1

func AppConfigDir() (string, error)

AppConfigDir returns default application config dir.

func AppDataDir added in v0.3.1

func AppDataDir() (string, error)

AppDataDir returns default application data dir.

func PrettyByteSize

func PrettyByteSize(b int) string

PrettyByteSize formats a byte size (int) into a human-readable colored string using binary prefixes (KiB, MiB, etc.).

func UseColour added in v0.2.1

func UseColour() bool

UseColour checks if output is a terminal or whether colour output has been suppresed in env.

func UserDataDir added in v0.3.0

func UserDataDir() (string, error)

UserDataDir returns the default root directory to use for user-specific data. Users should create their own application-specific subdirectory within this one and use that.

On Unix systems, it returns $XDG_DATA_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.local/share.

If the location cannot be determined (for example, $HOME is not defined) or the path in $XDG_DATA_HOME is relative, then it will return an error.

Types

This section is empty.

Directories

Path Synopsis
Package config reads a yaml config file from the XDG_CONFIG_HOME and unmarshals it into a user supplied struct
Package config reads a yaml config file from the XDG_CONFIG_HOME and unmarshals it into a user supplied struct
Package logging provides slog helpers.
Package logging provides slog helpers.
Package money is a simple currency package
Package money is a simple currency package

Jump to

Keyboard shortcuts

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