Documentation
¶
Index ¶
- Constants
- func All[T any](arr []T, predicate func(T) bool) bool
- func Any[T any](arr []T, predicate func(T) bool) bool
- func BeginOfDay(t time.Time) time.Time
- func BeginOfHour(t time.Time) time.Time
- func BeginOfMinute(t time.Time) time.Time
- func BeginOfMonth(t time.Time) time.Time
- func BeginOfWeek(t time.Time, beginFrom ...time.Weekday) time.Time
- func BeginOfYear(t time.Time) time.Time
- func BetweenSeconds(t1 time.Time, t2 time.Time) int64
- func ContainChinese(s string) bool
- func ContainLetter(str string) bool
- func ContainNumber(input string) bool
- func Contains[T comparable](arr []T, tar T) bool
- func Convert[S, T any](s []S, fn func(S) T) []T
- func DayOfYear(t time.Time) int
- func Dedup[T comparable](slice []T) []T
- func EndOfDay(t time.Time) time.Time
- func EndOfHour(t time.Time) time.Time
- func EndOfMinute(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EndOfWeek(t time.Time, endWith ...time.Weekday) time.Time
- func EndOfYear(t time.Time) time.Time
- func FileExists(filePath string) bool
- func FileSize(filePath string) (int64, error)
- func Filter[T any](arr []T, predicate func(T) bool) []T
- func FilterIter[inputs ~[]E, E any](arr inputs, fn func(E) bool) iter.Seq[E]
- func Find[T any](arr []T, predicate func(T) bool) (T, bool)
- func FirstDayOfMonth(date time.Time) time.Time
- func FirstDayOfWeek(date time.Time) time.Time
- func FormatDuration(duration time.Duration) string
- func GenerateRandomString(n int) string
- func GetLocalIP(ifaceName string) (string, error)
- func GetMacAddr(ifaceName string) (string, error)
- func GetSubnetMask(ifaceName string) (string, error)
- func GroupBy[T any, K comparable](arr []T, keyFunc func(T) K) map[K][]T
- func IsASCII(str string) bool
- func IsAlpha(str string) bool
- func IsBase64(base64 string) bool
- func IsBase64URL(v string) bool
- func IsBin(v string) bool
- func IsDns(dns string) bool
- func IsEmail(email string) bool
- func IsEmptyString(str string) bool
- func IsFloat(v any) bool
- func IsFloatStr(str string) bool
- func IsGBK(data []byte) bool
- func IsHex(v string) bool
- func IsInt(v any) bool
- func IsIntStr(str string) bool
- func IsIp(ipstr string) bool
- func IsIpV4(ipstr string) bool
- func IsIpV6(ipstr string) bool
- func IsJSON(str string) bool
- func IsJWT(v string) bool
- func IsLeapYear(year int) bool
- func IsNumber(v any) bool
- func IsNumberStr(s string) bool
- func IsPort(str string) bool
- func IsPrintable(str string) bool
- func IsRegexMatch(str, regex string) bool
- func IsStrongPassword(password string, length int) bool
- func IsUrl(str string) bool
- func IsWeakPassword(password string) bool
- func IsWeekend(t time.Time) bool
- func IsZeroValue(value any) bool
- func LastDayOfMonth(date time.Time) time.Time
- func LastDayOfWeek(date time.Time) time.Time
- func Map[T any, U any](arr []T, fn func(T) U) []U
- func MapIter[inputs ~[]E, E any, U any](arr inputs, fn func(E) U) iter.Seq[U]
- func Partition[T any](arr []T, predicate func(T) bool) ([]T, []T)
- func RandBool() bool
- func RandBoolSlice(length int) []bool
- func RandBytes(length int) []byte
- func RandFloat(min, max float64, precision int) float64
- func RandFloats(length int, min, max float64, precision int) []float64
- func RandFromGivenSlice[T any](slice []T) T
- func RandInt(min, max int) int
- func RandIntSlice(length, min, max int) []int
- func RandLower(length int) string
- func RandNumeral(length int) string
- func RandNumeralOrLetter(length int) string
- func RandSliceFromGivenSlice[T any](slice []T, num int, repeatable bool) []T
- func RandString(length int) string
- func RandStringSlice(charset string, sliceLen, strLen int) []string
- func RandStringWithLetter(letters string, length int) string
- func RandSymbolChar(length int) string
- func RandUniqueIntSlice(length, min, max int) []int
- func RandUpper(length int) string
- func Reduce[T any, U any](arr []T, initial U, fn func(acc U, v T) U) U
- func RoundToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
- func StartEndDay() (start, end time.Time)
- func StartEndMonth() (start, end time.Time)
- func StartEndWeek() (start, end time.Time)
- func StartOfDay(date time.Time) time.Time
- func StringSearch(text, pattern string, opts ...stringSearchOptFunc) int
- func WithBM() stringSearchOptFunc
- func WithBruteForce() stringSearchOptFunc
- func WithEngine(engine SearchEngine) stringSearchOptFunc
- func WithKMP() stringSearchOptFunc
- func WithKMPV2() stringSearchOptFunc
- func Zip[T1 any, T2 any](arr1 []T1, arr2 []T2) [][2]any
- func ZipIter[T1 any, T2 any, E [2]any](arr1 []T1, arrs []T2) iter.Seq[E]
- type BMSearchEngine
- type BruteForceSearchEngine
- type KMPSearchEngine
- type KMPSearchEngineV2
- type SearchEngine
- type Stack
Constants ¶
const ( MaximumCapacity = math.MaxInt>>1 + 1 Numeral = "0123456789" LowwerLetters = "abcdefghijklmnopqrstuvwxyz" UpperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" SymbolChars = "!@#$%^&*()_+-=[]{}|;':\",./<>?" AllChars = Numeral + LowwerLetters + UpperLetters + SymbolChars )
Variables ¶
This section is empty.
Functions ¶
func BeginOfDay ¶ added in v1.0.6
BeginOfDay return beginning hour time of day.
func BeginOfHour ¶ added in v1.0.6
BeginOfHour return beginning hour time of day.
func BeginOfMinute ¶ added in v1.0.6
BeginOfMinute return beginning minute time of day.
func BeginOfMonth ¶ added in v1.0.6
BeginOfMonth return beginning of month.
func BeginOfWeek ¶ added in v1.0.6
BeginOfWeek return beginning week, default week begin from Sunday.
func BeginOfYear ¶ added in v1.0.6
BeginOfYear return the date time at the begin of year.
func BetweenSeconds ¶ added in v1.0.6
BetweenSeconds returns the number of seconds between two times.
func ContainChinese ¶ added in v1.0.9
ContainChinese check if the string contain mandarin chinese.
func ContainLetter ¶ added in v1.0.9
ContainLetter check if the string contain at least one letter.
func ContainNumber ¶ added in v1.0.9
ContainNumber check if the string contain at least one number.
func Contains ¶ added in v1.0.9
func Contains[T comparable](arr []T, tar T) bool
func Dedup ¶ added in v1.1.17
func Dedup[T comparable](slice []T) []T
func EndOfMinute ¶ added in v1.0.6
EndOfMinute return end minute time of day.
func EndOfMonth ¶ added in v1.0.6
EndOfMonth return end of month.
func FileExists ¶
func FirstDayOfMonth ¶
FirstDayOfMonth Get the first day of the month in which the given time is located
func FormatDuration ¶
func GenerateRandomString ¶
GenerateRandomString Deprecated: Use RandString() instead.
func GetLocalIP ¶
func GetMacAddr ¶
func GetSubnetMask ¶
func GroupBy ¶
func GroupBy[T any, K comparable](arr []T, keyFunc func(T) K) map[K][]T
GroupBy groups elements in the slice by a specified key function
func IsBase64URL ¶ added in v1.0.9
IsBase64URL check if a give string is a valid URL-safe Base64 encoded string.
func IsEmptyString ¶ added in v1.0.9
IsEmptyString check if the string is empty.
func IsFloatStr ¶ added in v1.0.9
IsFloatStr check if the string can convert to a float.
func IsGBK ¶ added in v1.0.9
IsGBK check if data encoding is gbk Note: this function is implemented by whether double bytes fall within the encoding range of gbk, while each byte of utf-8 encoding format falls within the encoding range of gbk. Therefore, utf8.valid() should be called first to check whether it is not utf-8 encoding, and then call IsGBK() to check gbk encoding. like below *
data := []byte("你好") if utf8.Valid(data) { fmt.Println("data encoding is utf-8") }else if(IsGBK(data)) { fmt.Println("data encoding is GBK") } fmt.Println("data encoding is unknown")
*
func IsLeapYear ¶ added in v1.0.6
IsLeapYear check if param year is leap year or not.
func IsNumberStr ¶ added in v1.0.9
IsNumberStr check if the string can convert to a number.
func IsPrintable ¶ added in v1.0.9
IsPrintable checks if string is all printable chars.
func IsRegexMatch ¶ added in v1.0.9
IsRegexMatch check if the string match the regexp.
func IsStrongPassword ¶ added in v1.0.9
IsStrongPassword check if the string is strong password, if len(password) is less than the length param, return false Strong password: alpha(lower+upper) + number + special chars(!@#$%^&*()?><).
func IsWeakPassword ¶ added in v1.0.9
IsWeakPassword check if the string is weak password Weak password: only letter or only number or letter + number.
func IsZeroValue ¶ added in v1.0.9
IsZeroValue checks if value is a zero value.
func LastDayOfMonth ¶
LastDayOfMonth Get the last day of the month in which the given time is located
func RandBool ¶ added in v1.0.7
func RandBool() bool
RandBool generates a random boolean value (true or false).
func RandBoolSlice ¶ added in v1.0.7
RandBoolSlice generates a random boolean slice of specified length.
func RandFloat ¶ added in v1.0.7
RandFloat generate random float64 number between [min, max) with specific precision.
func RandFloats ¶ added in v1.0.7
RandFloats generate a slice of random float64 numbers of length that do not repeat.
func RandFromGivenSlice ¶ added in v1.0.7
func RandFromGivenSlice[T any](slice []T) T
RandFromGivenSlice generate a random element from given slice.
func RandIntSlice ¶ added in v1.0.7
RandIntSlice generates a slice of random integers. The generated integers are between min and max (exclusive).
func RandNumeral ¶ added in v1.0.7
RandNumeral generate a random numeral string of specified length.
func RandNumeralOrLetter ¶ added in v1.0.7
RandNumeralOrLetter generate a random numeral or alpha string of specified length.
func RandSliceFromGivenSlice ¶ added in v1.0.7
RandSliceFromGivenSlice generate a random slice of length num from given slice.
- If repeatable is true, the generated slice may contain duplicate elements.
func RandString ¶ added in v1.0.7
RandString generate random alphabeta string of specified length.
func RandStringSlice ¶ added in v1.0.7
RandString generate a slice of random string of length strLen based on charset. chartset should be one of the following: random.Numeral, random.LowwerLetters, random.UpperLetters random.Letters, random.SymbolChars, random.AllChars. or a combination of them.
func RandStringWithLetter ¶ added in v1.1.22
func RandSymbolChar ¶ added in v1.0.7
RandSymbolChar generate a random symbol char of specified length. symbol chars: !@#$%^&*()_+-=[]{}|;':\",./<>?.
func RandUniqueIntSlice ¶ added in v1.0.7
RandUniqueIntSlice generate a slice of random int of length that do not repeat.
func RoundToFloat ¶ added in v1.0.7
func RoundToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
func StartEndDay ¶ added in v1.0.23
func StartEndMonth ¶ added in v1.0.23
func StartEndWeek ¶ added in v1.0.23
func StringSearch ¶ added in v1.0.22
func WithBruteForce ¶ added in v1.0.24
func WithBruteForce() stringSearchOptFunc
func WithEngine ¶ added in v1.0.22
func WithEngine(engine SearchEngine) stringSearchOptFunc
Types ¶
type BMSearchEngine ¶ added in v1.0.24
type BMSearchEngine struct{}
func (*BMSearchEngine) Search ¶ added in v1.0.24
func (bm *BMSearchEngine) Search(text, pattern string) int
type BruteForceSearchEngine ¶ added in v1.0.24
type BruteForceSearchEngine struct{}
func (*BruteForceSearchEngine) Search ¶ added in v1.0.24
func (bf *BruteForceSearchEngine) Search(text, pattern string) int
type KMPSearchEngine ¶ added in v1.0.22
type KMPSearchEngine struct{}
func (*KMPSearchEngine) Search ¶ added in v1.0.22
func (k *KMPSearchEngine) Search(text, pattern string) int
type KMPSearchEngineV2 ¶ added in v1.0.24
type KMPSearchEngineV2 struct{}
func (*KMPSearchEngineV2) Search ¶ added in v1.0.24
func (k *KMPSearchEngineV2) Search(text, pattern string) int