lib

package
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: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExitSuccess is the successful exit status.
	//
	// It should be called on successful exit.
	ExitSuccess = 0

	// ExitFailure is the failing exit status.
	ExitFailure = 1
)
View Source
const (
	OneTrueDateFormat    = "2006-01-02T15:04:05-0700"
	DateShortFormat      = "2006-01-02"
	TimeShortFormat      = "15:04:05"
	TimeShorterFormat    = "15:04"
	TimeStandardDateTime = "2006-01-02 15:04"
)

Variables

This section is empty.

Functions

func Duration

func Duration(d time.Duration) string

Duration returns a prettier string for time.Durations.

func Err

func Err(exit int, err error, format string, a ...any)

Err displays a formatting error message to standard error, appending the error string, and exits with the status code from `exit`, à la err(3).

func Errx

func Errx(exit int, format string, a ...any)

Errx displays a formatted error message to standard error and exits with the status code from `exit`, à la errx(3).

func HexEncode added in v1.13.0

func HexEncode(b []byte, mode HexEncodeMode) string

HexEncode encodes the given bytes as a hexadecimal string. It also supports a few other binary-encoding formats as well.

func IsDigit added in v1.15.0

func IsDigit(b byte) bool

IsDigit checks if a byte is a decimal digit.

func Itoa

func Itoa(i int, wid int) string

Itoa provides cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding. Adapted from the 'itoa' function in the log/log.go file in the standard library.

func ParseDuration added in v1.15.0

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string into a time.Duration. It supports standard units (ns, us/µs, ms, s, m, h) plus extended units: d (days, 24h), w (weeks, 7d), y (years, 365d). Units can be combined without spaces, e.g., "1y2w3d4h5m6s". Case-insensitive. Years and days are approximations (no leap seconds/months). Returns an error for invalid input.

func ProgName

func ProgName() string

ProgName returns what lib thinks the program name is, namely the basename of argv0.

It is similar to the Linux __progname function.

func Warn

func Warn(err error, format string, a ...any) (int, error)

Warn displays a formatted error message to standard output, appending the error string, à la warn(3).

func Warnx

func Warnx(format string, a ...any) (int, error)

Warnx displays a formatted error message to standard error, à la warnx(3).

func WithCloser added in v1.16.0

func WithCloser(w io.Writer) io.WriteCloser

Types

type DummyWriteCloser added in v1.16.0

type DummyWriteCloser struct {
	// contains filtered or unexported fields
}

DummyWriteCloser wraps an io.Writer in a struct with a no-op Close.

func (*DummyWriteCloser) Close added in v1.16.0

func (dwc *DummyWriteCloser) Close() error

func (*DummyWriteCloser) Write added in v1.16.0

func (dwc *DummyWriteCloser) Write(p []byte) (int, error)

type FileTime

type FileTime struct {
	Changed  time.Time
	Modified time.Time
	Accessed time.Time
}

FileTime contains the changed, modified, and accessed timestamps for a file.

func LoadFileTime

func LoadFileTime(path string) (FileTime, error)

LoadFileTime returns a FileTime associated with the file.

type HexEncodeMode added in v1.13.0

type HexEncodeMode uint8
const (
	// HexEncodeLower prints the bytes as lowercase hexadecimal.
	HexEncodeLower HexEncodeMode = iota + 1
	// HexEncodeUpper prints the bytes as uppercase hexadecimal.
	HexEncodeUpper
	// HexEncodeLowerColon prints the bytes as lowercase hexadecimal
	// with colons between each pair of bytes.
	HexEncodeLowerColon
	// HexEncodeUpperColon prints the bytes as uppercase hexadecimal
	// with colons between each pair of bytes.
	HexEncodeUpperColon
	// HexEncodeBytes prints the string as a sequence of []byte.
	HexEncodeBytes
	// HexEncodeBase64 prints the string as a base64-encoded string.
	HexEncodeBase64
)

func ParseHexEncodeMode added in v1.13.0

func ParseHexEncodeMode(s string) HexEncodeMode

func (HexEncodeMode) String added in v1.13.0

func (m HexEncodeMode) String() string

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

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