util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MulanPSL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MD5Sum

func MD5Sum(r io.Reader) (string, error)

MD5Sum returns the MD5 checksum of the given reader.

func MD5SumFile

func MD5SumFile(path string) (string, error)

MD5SumFile returns the MD5 checksum of the given file.

func MD5SumStr

func MD5SumStr(content string) (string, error)

MD5SumStr returns the MD5 checksum of the given string.

func PathExists

func PathExists(path string) (bool, error)

PathExists check if the path exists

func RemoveEmptyElements

func RemoveEmptyElements[T any](arr []T) []T

RemoveEmptyElements removes empty elements (nil or empty string) from the array and returns the resulting array.

func SHA1Sum

func SHA1Sum(r io.Reader) (string, error)

SHA1Sum returns the SHA1 checksum of the given reader.

func SHA1SumFile

func SHA1SumFile(path string) (string, error)

SHA1SumFile returns the SHA1 checksum of the given file.

func SHA1SumStr

func SHA1SumStr(content string) (string, error)

SHA1SumStr returns the SHA1 checksum of the given string.

func SHA256Sum

func SHA256Sum(r io.Reader) (string, error)

SHA256Sum returns the SHA256 checksum of the given reader.

func SHA256SumFile

func SHA256SumFile(path string) (string, error)

SHA256SumFile returns the SHA256 checksum of the given file.

func SHA256SumStr

func SHA256SumStr(content string) (string, error)

SHA256SumStr returns the SHA256 checksum of the given string.

func SM3Sum

func SM3Sum(r io.Reader) (string, error)

SM3Sum returns the SM3 checksum of the given reader. The SM3 algorithm is a hash algorithm promulgated by the Chinese government. For details, please refer to https://www.oscca.gov.cn/sca/xxgk/2010-12/17/content_1002389.shtml

func SM3SumFile

func SM3SumFile(path string) (string, error)

SM3SumFile returns the SM3 checksum of the given file.

func SM3SumStr

func SM3SumStr(content string) (string, error)

SM3SumStr returns the SM3 checksum of the given string.

func SliceAll

func SliceAll[T any](in []T, test func(T) bool) bool

SliceAll returns true if all elements match the test function.

func SliceAny

func SliceAny[T any](in []T, test func(T) bool) bool

SliceAny returns true if any element matches the test function.

func SliceContains

func SliceContains[T comparable](in []T, target T) bool

SliceContains returns true if the slice contains the element.

func SliceContainsFunc

func SliceContainsFunc[T any](in []T, target T, equal func(T, T) bool) bool

SliceContainsFunc returns true if the slice contains the element using the equal function.

func SliceCount

func SliceCount[T any](in []T, test func(T) bool) int

func SliceEach

func SliceEach[T any](in []T, fn func(T))

SliceEach iterates over the slice and calls the function for each element.

func SliceEqual

func SliceEqual[T any](in1 []T, in2 []T, equal func(T, T) bool) bool

SliceEqual returns true if the two slices are equal. The equal function is used to compare the elements.

func SliceFilter

func SliceFilter[T any](in []T, filter func(T) bool) []T

SliceFilter filters the slice using the filter function.

func SliceFirst

func SliceFirst[T any](in []T, test func(T) bool) int

SliceFirst returns the index of the first element that matches the test function.

func SliceFlatMap

func SliceFlatMap[T any, R any](in []T, convert func(T) []R) []R

SliceFlatMap maps the slice using the convert function and flattens the result.

func SliceGroup

func SliceGroup[T any, K comparable](in []T, getKey func(T) K) map[K][]T

SliceGroup groups the slice using the getKey function.

func SliceLast

func SliceLast[T any](in []T, test func(T) bool) int

SliceLast returns the index of the last element that matches the test function.

func SliceMap

func SliceMap[T any, R any](in []T, convert func(T) R) []R

SliceMap maps the slice using the convert function.

func SliceNone

func SliceNone[T any](in []T, test func(T) bool) bool

SliceNone returns true if no elements match the test function.

func SliceReduce

func SliceReduce[T any, R any](in []T, init R, fn func(T, R) R) R

SliceReduce reduces the slice to a single value using the init value and the reduce function. The reduce function is called with the current value and the accumulator.

func SliceSort

func SliceSort[T any](in []T, less func(i, j T) bool) []T

SliceSort sorts the slice in place using the less function.

func SliceToMap

func SliceToMap[T any, K comparable, V any](in []T, getKey func(T) K, getValue func(T) V, combiner func(V, V) V) map[K]V

SliceToMap maps the slice using the getKey and getValue functions. If the key is already present, the combiner function is used to combine the values.

func SliceUnique

func SliceUnique[T comparable](in []T) []T

SliceUnique returns a slice with unique elements. The combine function is used to combine the values.

func SliceUniqueFunc

func SliceUniqueFunc[T any](in []T, combine func(T, T) T, equal func(T, T) bool) []T

SliceUniqueFunc returns a slice with unique elements. The combine function is used to combine the values. The equal function is used to determine if two elements are equal.

func VerifyCode

func VerifyCode[T any](items []T, line func(T) string) string

VerifyCode returns the verification code(SHA1 checksum) of lines converted from items.

func WalkFilesWithMatcher

func WalkFilesWithMatcher(path string, doneChan <-chan struct{}, ignoreMatcher *pattern_set.PatternSet, hitMatcher *pattern_set.PatternSet) (<-chan string, <-chan error)

WalkFilesWithMatcher walks the file tree rooted at path, sending the paths of all regular files to pathChan. If ignoreMatcher is not nil, files matching the ignoreMatcher will be ignored. If hitMatcher is not nil, only files matching the hitMatcher will be sent to pathChan. If an error is encountered, it will be sent to errChan. If doneChan is closed, the walk process will be canceled.

func WriteToJSONFile

func WriteToJSONFile(path string, obj interface{}) error

WriteToJSONFile writes the obj to a json file

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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