stdx

package
v0.0.50 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package stdx holds small, dependency-free utilities shared across the module: environment lookups with defaults, file-system probes, and generic map, slice and string operations. It is a leaf: it imports nothing from the module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T any](v any) T

As returns v as a T, or T's zero value when v does not hold one: the comma-ok assertion for call sites where absence and a wrong type mean the same thing.

func AsMap

func AsMap(v any) map[string]any

AsMap asserts an arbitrary value (e.g. a range element) to map[string]any, returning nil when it is not a map — the value-based analogue of GetMap.

func DirExists

func DirExists(path string) bool

DirExists reports whether path exists and is a directory.

func FileExists

func FileExists(path string) bool

FileExists reports whether path exists and is a regular file (not a directory).

func GetMap

func GetMap(m map[string]any, k string) map[string]any

GetMap returns m[k] as a map[string]any, or nil if the key is absent or not a map.

func GetSlice

func GetSlice(m map[string]any, k string) []any

GetSlice returns m[k] as a []any, or nil if the key is absent or not a slice.

func GetString

func GetString(m map[string]any, k string) string

GetString returns m[k] as a string, or "" if the key is absent or not a string.

func IsAllDigits

func IsAllDigits(text string) bool

IsAllDigits reports whether s is non-empty and every byte is an ASCII digit.

func IsHex

func IsHex(text string) bool

IsHex reports whether s is non-empty and every byte is an ASCII hexadecimal digit (0-9, a-f, A-F).

func IsUUID

func IsUUID(text string) bool

IsUUID reports whether s is a canonical 8-4-4-4-12 hyphenated UUID: 36 bytes, ASCII hex with hyphens at positions 8, 13, 18, and 23.

func OrDefault

func OrDefault(key, fallback string) string

OrDefault returns the value of the environment variable named key, or fallback if the variable is unset or empty.

func Truncate

func Truncate(s string, limit int) string

Truncate returns s truncated to at most limit runes. If s fits within limit, it is returned unchanged.

func Unique

func Unique[T comparable](s []T) []T

Unique returns a new slice containing only the first occurrence of each element, preserving order.

func UniqueDirs

func UniqueDirs(paths []string) []string

UniqueDirs extracts the directory component of each path in paths and returns the unique set, preserving order of first occurrence.

func Zero

func Zero[T any]() T

Zero returns the zero value of T. It names "nothing to report" for a struct type, where an empty composite literal would read as a value with its fields forgotten.

Types

This section is empty.

Jump to

Keyboard shortcuts

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