common-lang-in-go
https://github.com/sjsdfg/common-lang-in-go
Java 程序员编写的类似 common-lang 工具包
包名就是要用大驼峰,不想改成 go 规范的包名。自己写的任性
how to use
go get github.com/sjsdfg/common-lang-in-go
StringUtils
- IsEmpty(str string) bool
- IsNotEmpty(str string) bool
- IsAllEmpty(list …string) bool
- IsAnyEmpty(list …string) bool
- IsAnyNoneEmpty(list …string) bool
- IsBlank(str string) bool
- IsNotBlank(str string) bool
- IsZero(str string) bool
- IsNotZero(str string) bool
- IsAnyZero(list …string) bool
- IsAllZero(list …string) bool
- IsAnyNoneZero(list …string) bool
- Equal(str1, str2 string) bool
- EqualIgnoreCase(str1, str2 string) bool
- EqualsAny(str string, list …string) bool
- EqualsAnyIgnoreCase(str string, list …string) bool
- IsDigital(str string) bool
- DefaultIfEmpty(str, defaultStr string) string
- If(condition bool, ifTrue, ifFalse string) string
- Truncate(str string, startIndex, endIndex int) string
CollectionUtils
match functions
- AllMatch(list interface{}, action matchFunc) bool
- AnyMatch(list interface{}, action matchFunc) bool
- NoneMatch(list interface{}, action matchFunc) bool
Use Case
func TestAllMatch(t *testing.T) {
testCase := []string{
"a", "a", "a"}
assert.Equal(t, true, AllMatch(testCase, func(index int) bool {
return testCase[index] == "a"
}))
testCase = []string{
"a", "a", "b"}
assert.Equal(t, false, AllMatch