Help us shape the future of Go! Take the 2026 Go Developer Survey

helpers

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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(s string) bool

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

func IsHex

func IsHex(s 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(s 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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