util

package
v1.1303.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package util implements utility functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreValuesEqual added in v1.1303.0

func AreValuesEqual(a, b any) bool

AreValuesEqual safely compares two values, handling slices and other uncomparable types

func ChannelToSlice

func ChannelToSlice[t any](channel <-chan t) []t

ChannelToSlice converts a channel to a slice by reading all values from the channel.

func ConvertToUTF8 added in v1.1303.0

func ConvertToUTF8(reader io.Reader) ([]byte, error)

func DumpGoroutines added in v1.1303.0

func DumpGoroutines(logger *zerolog.Logger)

func GetIssueKey

func GetIssueKey(ruleId string, path string, startLine int, endLine int, startCol int, endCol int) string

func Hash

func Hash(content []byte) string

func HashWithoutConversion added in v1.1303.0

func HashWithoutConversion(content []byte) string

func Ignored

func Ignored(gitIgnore *ignore.GitIgnore, path string) bool

func IsChannelClosed

func IsChannelClosed[T any](ch <-chan T) bool

func IsEmptyValue added in v1.1303.0

func IsEmptyValue(value any) bool

IsEmptyValue checks if a value is considered empty

func Max

func Max[T ordered](values ...T) T

func Min

func Min[T ordered](values ...T) T

func PathKey added in v1.1303.0

func PathKey(p types.FilePath) types.FilePath

PathKey creates a normalized key for path storage

func Ptr added in v1.1303.0

func Ptr[T any](v T) *T

Ptr returns a pointer to the input value. Because in Go you can't do something like `takesPtr(&(returnsStruct()))`. So instead do `takesPtr(Ptr(returnsStruct()))`.

func Result

func Result[t any](value t, _ error) t

Result returns the result of a function call and ignores the error. This saves lines when you don't care about the error and want to inline the call.

For example, instead of writing: val, _ := someFunc() foo(val)

You can write: foo(Result(someFunc()))

func Sha256First16Hash

func Sha256First16Hash(input string) string

func SlicesEqualIgnoringOrder added in v1.1303.0

func SlicesEqualIgnoringOrder[T cmp.Ordered](a, b []T) bool

SlicesEqualIgnoringOrder compares two slices for equality ignoring element order

func ValidatePath added in v1.1303.0

func ValidatePath(path types.FilePath, options PathValidationOptions) error

ValidatePath validates any path for security with customizable requirements

func ValidatePathForStorage added in v1.1303.0

func ValidatePathForStorage(path types.FilePath) error

ValidatePathForStorage validates a path for storage purposes without requiring the path to exist. This function is used when storing paths where the path may not exist yet (e.g., user-configured paths for future use, paths during data migration, or storage keys). It allows empty paths and doesn't check if the path actually exists on the filesystem.

func ValidatePathLenient added in v1.1303.0

func ValidatePathLenient(path types.FilePath) error

ValidatePathLenient validates a path with lenient requirements (allows empty, no existence check)

func ValidatePathStrict added in v1.1303.0

func ValidatePathStrict(path types.FilePath) error

ValidatePathStrict validates a path with strict requirements (no empty, must be directory)

Types

type ExistenceType added in v1.1303.0

type ExistenceType int

ExistenceType defines what type of existence validation to perform

const (
	NoCheck ExistenceType = iota
	ExistAsFileOrDirectory
	ExistAsDirectory
	ExistAsFile
)

type PathValidationOptions added in v1.1303.0

type PathValidationOptions struct {
	AllowEmpty bool
	Existence  ExistenceType
}

PathValidationOptions defines validation requirements for paths

Jump to

Keyboard shortcuts

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