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

util

package
v0.16.0 Latest Latest
Warning

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

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

Documentation

Overview

Package util holds small helpers shared across packages so a single implementation is imported everywhere rather than duplicated.

Index

Constants

This section is empty.

Variables

View Source
var ErrStatePath = errors.New("no default state directory")

ErrStatePath indicates no default state directory can be derived for this user.

Functions

func DefaultStatePath added in v0.16.0

func DefaultStatePath() (string, error)

DefaultStatePath returns the file fleetsweeper keeps its scan store in when none is named: $XDG_STATE_HOME/fleetsweeper/fleet.db when XDG_STATE_HOME is absolute, else ~/.local/state/fleetsweeper/fleet.db, and the user config directory on Windows.

func Fingerprint

func Fingerprint(cluster, scanner, rule string) string

Fingerprint returns a stable hex identifier for a finding, derived from the cluster, scanner, and rule separated by null bytes. The rule names the check rather than its wording, so a finding keeps its fingerprint when a count in its title changes. Acknowledgements key on the same value, so a finding can be matched to its ack and tracked across scans by fingerprint.

func Float64 added in v0.13.0

func Float64(v any) (float64, bool)

Float64 converts a numeric value to float64. It accepts the float64 that JSON decoding produces and the float32 and int variants hand-built maps carry, and reports false for anything else.

func Median added in v0.13.0

func Median(vals []float64) float64

Median returns the median of vals without reordering it, averaging the middle pair for an even count. It returns 0 for empty input.

func Plural added in v0.10.0

func Plural(n int) string

Plural returns "s" when n is not 1 and the empty string otherwise.

func SanitizeName added in v0.10.0

func SanitizeName(name string) string

SanitizeName returns a DNS-1123-safe rendering of name suitable for use as a Kubernetes metadata.name value. It lowercases, replaces runs of invalid characters with a dash, collapses adjacent dashes, caps the result at 253 characters, and trims dashes and dots from both ends so the name starts and ends alphanumeric. Pass any fixed prefix as part of name so the cap covers it.

func SeverityAtLeast added in v0.10.0

func SeverityAtLeast(got, want string) bool

SeverityAtLeast reports whether got meets the want threshold. An empty want always passes.

func SeverityRank added in v0.10.0

func SeverityRank(s string) int

SeverityRank assigns a numeric weight to a severity string for comparison. Unknown values rank 0.

func Truncate added in v0.10.0

func Truncate(s string, n int) string

Truncate shortens s to at most n runes, appending an ellipsis when cut.

Types

This section is empty.

Jump to

Keyboard shortcuts

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