Documentation
¶
Overview ¶
Package util implements utility functions
Index ¶
- func AreValuesEqual(a, b any) bool
- func ChannelToSlice[t any](channel <-chan t) []t
- func ConvertToUTF8(reader io.Reader) ([]byte, error)
- func DumpGoroutines(logger *zerolog.Logger)
- func GetIssueKey(ruleId string, path string, startLine int, endLine int, startCol int, ...) string
- func GetUserAgent(c configuration.Configuration, version string) networking.UserAgentInfo
- func Hash(content []byte) string
- func HashWithoutConversion(content []byte) string
- func Ignored(gitIgnore *ignore.GitIgnore, path string) bool
- func IsChannelClosed[T any](ch <-chan T) bool
- func IsEmptyValue(value any) bool
- func Max[T ordered](values ...T) T
- func Min[T ordered](values ...T) T
- func PathKey(p types.FilePath) types.FilePath
- func Ptr[T any](v T) *T
- func Result[t any](value t, _ error) t
- func Sha256First16Hash(input string) string
- func SlicesEqualIgnoringOrder[T cmp.Ordered](a, b []T) bool
- func ValidatePath(path types.FilePath, options PathValidationOptions) error
- func ValidatePathForStorage(path types.FilePath) error
- func ValidatePathLenient(path types.FilePath) error
- func ValidatePathStrict(path types.FilePath) error
- type ExistenceType
- type PathValidationOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreValuesEqual ¶ added in v1.1303.0
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 DumpGoroutines ¶ added in v1.1303.0
func GetIssueKey ¶
func GetUserAgent ¶
func GetUserAgent(c configuration.Configuration, version string) networking.UserAgentInfo
func HashWithoutConversion ¶ added in v1.1303.0
func IsChannelClosed ¶
func IsEmptyValue ¶ added in v1.1303.0
IsEmptyValue checks if a value is considered empty
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 ¶
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 SlicesEqualIgnoringOrder ¶ added in v1.1303.0
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
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
ValidatePathLenient validates a path with lenient requirements (allows empty, no existence check)
func ValidatePathStrict ¶ added in v1.1303.0
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