util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDNSResolution

func CheckDNSResolution(ctx context.Context, host string) (time.Duration, error)

CheckDNSResolution verifies if DNS resolution works and measures resolution latency.

func CheckTCPConnectivity

func CheckTCPConnectivity(ctx context.Context, address string, timeout time.Duration) (time.Duration, error)

CheckTCPConnectivity verifies TCP connectivity to a host:port and measures latency.

func FormatBytes

func FormatBytes(b uint64) string

FormatBytes converts raw bytes into human readable binary units (B, KiB, MiB, GiB, TiB).

func FormatDecimalBytes

func FormatDecimalBytes(b uint64) string

FormatDecimalBytes converts raw bytes into decimal units (B, KB, MB, GB, TB).

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration concisely (e.g. "3d 4h 12m 5s").

func FormatRate

func FormatRate(bytesPerSec float64) string

FormatRate formats bytes per second.

func RenderProgressBar

func RenderProgressBar(pct float64, width int) string

RenderProgressBar generates an ASCII progress meter like [████████░░░░░░░░] 50.0%

func TruncateString

func TruncateString(s string, maxLen int) string

TruncateString truncates a string to maxLen with an ellipsis.

Types

type TableWriter

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

TableWriter formats rows and columns into cleanly aligned CLI text.

func NewTableWriter

func NewTableWriter(headers ...string) *TableWriter

NewTableWriter creates a new table writer.

func (*TableWriter) Append

func (t *TableWriter) Append(cols ...string)

Append adds a row of values.

func (*TableWriter) Render

func (t *TableWriter) Render(w io.Writer)

Render writes the formatted table to w.

Jump to

Keyboard shortcuts

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