Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js.
English | 简体ä¸ć–‡
- 👏 Comprehensive, efficient and reusable.
- đź’Ş 400+ go util functions, support string, slice, datetime, net, crypt...
- đź’… Only depend on the go standard library.
- 🌍 Unit test for every exported function.
go get github.com/duke-git/lancet
Lancet organizes the code into package structure, and you need to import the corresponding package name when use it. For example, if you use string-related functions,import the strutil package like below:
import "github.com/duke-git/lancet/strutil"
Here takes the string function Reverse (reverse order string) as an example, and the strutil package needs to be imported.
package main
import (
"fmt"
"github.com/duke-git/lancet/strutil"
)
func main() {
s := "hello"
rs := strutil.Reverse(s)
fmt.Println(rs) //olleh
}
import "github.com/duke-git/lancet/compare"
import "github.com/duke-git/lancet/convertor"
- ColorHexToRGB
- ColorRGBToHex
- ToBool
- ToBytes
- ToChar
- ToChannel
- ToInt
- ToJson
- ToString
- StructToMap
- MapToStruct
- EncodeByte
- DecodeByte
- DeepClone
- CopyProperties
- ToInterface
- Utf8ToGbk
- GbkToUtf8
- ToStdBase64
- ToUrlBase64
- ToRawStdBase64
- ToRawUrlBase64
import "github.com/duke-git/lancet/cryptor"
- AesEcbEncrypt
- AesEcbDecrypt
- AesCbcEncrypt
- AesCbcDecrypt
- AesCtrCrypt
- AesCfbEncrypt
- AesCfbDecrypt
- AesOfbEncrypt
- AesOfbDecrypt
- Base64StdEncode
- Base64StdDecode
- DesEcbEncrypt
- DesEcbDecrypt
- DesCbcEncrypt
- DesCbcDecrypt
- DesCtrCrypt
- DesCfbEncrypt
- DesCfbDecrypt
- DesOfbEncrypt
- DesOfbDecrypt
- HmacMd5
- HmacMd5WithBase64
- HmacSha1
- HmacSha1WithBase64
- HmacSha256
- HmacSha256WithBase64
- HmacSha512
- HmacSha512WithBase64
- Md5String
- Md5StringWithBase64
- Md5Byte
- Md5ByteWithBase64
- Md5File
- Sha1
- Sha1WithBase64
- Sha256
- Sha256WithBase64
- Sha512
- Sha512WithBase64
- GenerateRsaKey
- RsaEncrypt
- RsaDecrypt
- GenerateRsaKeyPair
- RsaEncryptOAEP
- RsaDecryptOAEP
import "github.com/duke-git/lancet/datetime"
- AddDay
- AddHour
- AddMinute
- AddYear
- BeginOfMinute
- BeginOfHour
- BeginOfDay
- BeginOfWeek
- BeginOfMonth
- BeginOfYear
- EndOfMinute
- EndOfHour
- EndOfDay
- EndOfWeek
- EndOfMonth
- EndOfYear
- GetNowDate
- GetNowTime
- GetNowDateTime
- GetZeroHourTimestamp
- GetNightTimestamp
- FormatTimeToStr
- FormatStrToTime
- NewUnix
- NewUnixNow
- NewFormat
- NewISO8601
- ToUnix
- ToFormat
- ToFormatForTpl
- ToIso8601
- IsLeapYear
- BetweenSeconds
- DayOfYear
- IsWeekend
- NowDateOrTime
- Timestamp
- TimestampMilli
- TimestampMicro
- TimestampNano
- TrackFuncTime
- DaysBetween
- GenerateDatetimesBetween
import "github.com/duke-git/lancet/fileutil"
- ClearFile
- CreateFile
- CreateDir
- CopyFile
- FileMode
- MiMeType
- IsExist
- IsLink
- IsDir
- ListFileNames
- RemoveFile
- ReadFileToString
- ReadFileByLine
- Zip
- ZipAppendEntry
- UnZip
- CurrentPath
- IsZipFile
- FileSize
- MTime
- Sha
- ReadCsvFile
- WriteCsvFile
- WriteMapsToCsv
- WriteStringToFile
- WriteBytesToFile
- ReadFile
import "github.com/duke-git/lancet/formatter"
7. Function package can control the flow of function execution and support part of functional programming
import "github.com/duke-git/lancet/function"
import "github.com/duke-git/lancet/mathutil"
- Exponent
- Fibonacci
- Factorial
- Percent
- RoundToFloat
- RoundToString
- TruncRound
- CeilToFloat
- CeilToString
- FloorToFloat
- FloorToString
- AngleToRadian
- RadianToAngle
- PointDistance
- IsPrime
- GCD
- LCM
- Cos
- Sin
- Log
import "github.com/duke-git/lancet/netutil"
- ConvertMapToQueryString
- EncodeUrl
- GetInternalIp
- GetIps
- GetMacAddrs
- GetPublicIpInfo
- GetRequestPublicIp
- IsPublicIP
- IsInternalIP
- HttpGet
- HttpDelete
- HttpPost
- HttpPut
- HttpPatch
- ParseHttpResponse
- UploadFile
- DownloadFile
- IsPingConnected
- IsTelnetConnected
import "github.com/duke-git/lancet/random"
- RandBool
- RandBoolSlice
- RandBytes
- RandInt
- RandIntSlice
- RandString
- RandStringSlice
- RandFloat
- RandFloats
- RandUpper
- RandLower
- RandNumeral
- RandNumeralOrLetter
- UUIdV4
- RandUniqueIntSlice
11. Retry package is for executing a function repeatedly until it was successful or canceled by the context.
import "github.com/duke-git/lancet/retry"
import "github.com/duke-git/lancet/slice"
- AppendIfAbsent
- Contain
- ContainSubSlice
- Chunk 5C99 li>
- Compact
- Concat
- Count
- Difference
- DifferenceBy
- DeleteByIndex
- Drop
- Every
- Equal
- EqualWith
- Filter
- Find
- FindLast
- FlattenDeep
- ForEach
- GroupBy
- IntSlice
- IndexOf
- LastIndexOf
- InterfaceSlice
- Intersection
- InsertByIndex
- Map
- ReverseSlice
- Reduce
- Shuffle
- SortByField
- Some
- StringSlice
- ToSlice
- ToSlicePointer
- Unique
- UniqueBy
- Union
- UpdateByIndex
- Without
- Join
import "github.com/duke-git/lancet/strutil"
- After
- AfterLast
- Before
- BeforeLast
- CamelCase
- Capitalize
- ContainsAll
- ContainsAny
- IsString
- KebabCase
- UpperKebabCase
- LowerFirst
- UpperFirst
- Pad
- PadEnd
- PadStart
- Reverse
- SnakeCase
- UpperSnakeCase
- SplitEx
- Wrap
- Unwrap
- SplitWords
- WordCount
- RemoveNonPrintable
- StringToBytes
- BytesToString
- IsBlank
- HasPrefixAny
- HasSuffixAny
- IndexOffset
- ReplaceWithMap
- Trim
- SplitAndTrim
- HideString
- RemoveWhiteSpace
- SubInBetween
- HammingDistance
- Concat
- Ellipsis
- Shuffle
- Rotate
- TemplateReplace
- RegexMatchAllGroups
import "github.com/duke-git/lancet/system"
import "github.com/duke-git/lancet/validator"
- ContainChinese
- ContainLetter
- ContainLower
- ContainUpper
- IsAlpha
- IsAllUpper
- IsAllLower
- IsBase64
- IsChineseMobile
- IsChineseIdNum
- IsChinesePhone
- IsCreditCard
- IsDns
- IsEmail
- IsEmptyString
- IsInt
- IsFloat
- IsNumber
- IsIntStr
- IsFloatStr
- IsNumberStr
- IsJSON
- IsRegexMatch
- IsIp
- IsIpV4
- IsIpV6
- IsStrongPassword
- IsUrl
- IsWeakPassword
- IsZeroValue
- IsGBK
- IsASCII
- IsPrintable
- IsBin
- IsHex
- IsBase64URL
- IsJWT
- IsVisa
- IsMasterCard
- IsAmericanExpress
- IsUnionPay
- IsChinaUnionPay
I really appreciate any code commits which make lancet lib powerful. Please follow the rules below to create your pull request.
- Fork the repository.
- Create your feature branch.
- Commit your changes.
- Push to the branch
- Create new pull request.