kit

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T any](value any, fallback T) T

As returns value as a T, or fallback when it is nil or holds another type.

func AsStringMap

func AsStringMap(value any) (map[string]any, bool)

AsStringMap converts any map with string or interface keys, including named map types, to map[string]any. Entries whose key is not a string are dropped. The second result is false when value is not such a map.

func Capitalize

func Capitalize(s string) string

Capitalize upper-cases the first rune of s.

func Collect

func Collect[T any](value any, mapper func(any) T) []T

Collect maps value through mapper, treating any slice or array as its elements and anything else (including []byte) as a single item. A nil value yields nil.

func CompareAddresses

func CompareAddresses(a, b string) int

CompareAddresses orders IP address strings numerically, ignoring any CIDR suffix. Empty values sort first and malformed values last in string order.

func CompareSubnets

func CompareSubnets(a, b string) int

CompareSubnets orders CIDR strings by masked network address, then prefix length. Empty values sort first and malformed values last in string order.

func EnsurePrefix

func EnsurePrefix(s, prefix string) string

EnsurePrefix trims s and returns it unchanged when it already starts with prefix, otherwise prefix+s.

func FilePathMatches

func FilePathMatches(relativePath, rootPath string) bool

FilePathMatches reports whether relativePath is rootPath or lies beneath it.

func Fingerprint

func Fingerprint(values ...any) uint64

Fingerprint returns an order-sensitive FNV-1a hash of values for change detection. Strings are NUL-terminated, integers varint-encoded, time.Time hashed by UnixNano, nil pointers tagged absent and non-nil ones present plus the value, slices and arrays prefixed by length, structs walked by exported field, and maps hashed in sorted key order. It is not collision resistant and must never back a security decision.

func FromPtr

func FromPtr[T any](ptr *T) T

FromPtr returns the pointed-to value, or T's zero value if ptr is nil.

func GetImageMimeType

func GetImageMimeType(ext string) string

func LookupEnvOrFile added in v0.6.0

func LookupEnvOrFile(name string) (value string, found, fromFile bool)

LookupEnvOrFile is os.LookupEnv with Docker secret support: when NAME__FILE or NAME_FILE (checked in that order) names a readable file, its trimmed contents stand in for NAME. An unreadable file falls back to NAME. The booleans report whether a value was found and whether it came from a file.

func NormalizeRelativePath

func NormalizeRelativePath(input string) (string, error)

NormalizeRelativePath validates and cleans a slash-delimited path rooted at a managed file tree. The result never begins with a slash or escapes the root.

func ParseBool

func ParseBool(value string) (bool, bool)

ParseBool recognizes true/1/yes/on and false/0/no/off, ignoring case and whitespace. The second result reports whether the value is recognized.

func ParseOrDefault

func ParseOrDefault[T any](value string, defaultValue T, parse func(string) (T, error)) T

ParseOrDefault parses value using parse, falling back to defaultValue when empty or unparseable.

func RandomString

func RandomString(length int) string

RandomString returns length URL-safe base64 characters drawn from crypto/rand.

func SHA256Hex

func SHA256Hex[T string | []byte](s T) string

SHA256Hex returns the hex-encoded SHA-256 digest of s.

func SQLitePathFromDSN

func SQLitePathFromDSN(dsn string) (string, error)

SQLitePathFromDSN returns the filesystem portion of a SQLite file DSN. "file:data/arcane.db?..." carries the path in Opaque, "file:/abs/path.db" in Path.

func SanitizeBrowsePath

func SanitizeBrowsePath(input string) (string, error)

SanitizeBrowsePath cleans a path within a rooted file browser to an absolute form, rejecting traversal above the root.

func SnakeCase

func SnakeCase(s string) string

SnakeCase lower-cases s, inserting an underscore before every upper-case rune after the first.

func Ternary

func Ternary[T any](condition bool, trueVal, falseVal T) T

func ToString

func ToString(v any) string

ToString converts any value to a trimmed string.

func TrimNonEmpty

func TrimNonEmpty(values []string) []string

TrimNonEmpty trims every entry and drops the blank ones, preserving order.

func TrimQuotes

func TrimQuotes(s string) string

TrimQuotes removes one matching pair of surrounding double or single quotes.

func Unique

func Unique[S ~[]E, E comparable](items S) S

Unique returns the distinct items in first-seen order, or nil when items is empty.

func ValidateFileName

func ValidateFileName(name string) (string, error)

ValidateFileName validates a single file-tree path segment.

func WriteRecord

func WriteRecord(w io.Writer, fields ...any)

WriteRecord writes fields NUL-separated and newline-terminated, for stable content hashes.

Types

This section is empty.

Directories

Path Synopsis
acfs module
builds module
Package capture provides a bounded, concurrency-safe capture buffer for streamed output such as build or process logs.
Package capture provides a bounded, concurrency-safe capture buffer for streamed output such as build or process logs.
docker module
convert module
fs
Package fs contains focused filesystem helpers shared by Arcane Go modules.
Package fs contains focused filesystem helpers shared by Arcane Go modules.
atomic
Package atomic provides crash-safe atomic file writes at an absolute path.
Package atomic provides crash-safe atomic file writes at an absolute path.
Package git provides helpers for recognizing and normalizing Git repository URLs across the schemes Git supports (scp-like git@, git, ssh, http, and https).
Package git provides helpers for recognizing and normalizing Git repository URLs across the schemes Git supports (scp-like git@, git, ssh, http, and https).
Package mapping deep-copies between structurally similar types, converting netip values to and from their string form along the way.
Package mapping deep-copies between structurally similar types, converting netip values to and from their string form along the way.
Package normalization applies opt-in Unicode NFC and whitespace normalization.
Package normalization applies opt-in Unicode NFC and whitespace normalization.
Package registry canonicalizes container registry hosts so that image references and credential lookups agree on what "the same registry" means.
Package registry canonicalizes container registry hosts so that image references and credential lookups agree on what "the same registry" means.
sys
bytes
Package bytes implements functionality for working with byte sizes.
Package bytes implements functionality for working with byte sizes.
cgroup module
tripwire module
updater module
Package utils provides focused helpers for working with string slices whose entries may be blank.
Package utils provides focused helpers for working with string slices whose entries may be blank.

Jump to

Keyboard shortcuts

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