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.
- 💪 180+ 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 ReverseStr (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.ReverseStr(s)
fmt.Println(rs) //olleh
}
import "github.com/duke-git/lancet/convertor"
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
- HmacSha1
- HmacSha256
- HmacSha512
- Md5String
- Md5File
- Sha1
- Sha256
- Sha512
- GenerateRsaKey
- RsaEncrypt
- RsaDecrypt
import "github.com/duke-git/lancet/datetime"
- AddDay
- AddHour
- AddMinute
- BeginOfMinute
- BeginOfHour
- BeginOfDay
- BeginOfWeek
- BeginOfMonth
- BeginOfYear
- EndOfMinute
- EndOfHour
- EndOfDay
- EndOfWeek
- EndOfMonth
- EndOfYear
- GetNowDate
- GetNowTime
- GetNowDateTime
- GetZeroHourTimestamp
- GetNightTimestamp
- FormatTimeToStr
- FormatStrToTime
import "github.com/duke-git/lancet/fileutil"
- ClearFile
- CreateFile
- CopyFile
- FileMode
- MiMeType
- IsExist
- IsLink
- IsDir
- ListFileNames
- RemoveFile
- ReadFileToString
- ReadFileByLine
- Zip
- UnZip
import "github.com/duke-git/lancet/formatter"
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"
import "github.com/duke-git/lancet/netutil"
- ConvertMapToQueryString
- GetInternalIp
- GetIps
- GetMacAddrs
- GetPublicIpInfo
- IsPublicIP
- HttpGet
- HttpDelete
- HttpPost
- HttpPut
- HttpPatch
- ParseHttpResponse
import "github.com/duke-git/lancet/random"
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"
- Contain
- ContainSubSlice
- Chunk
- Compact
- Concat
- Count
- Difference
- DifferenceBy
- DeleteByIndex
- Drop
- Every
- Filter
- Find
- FindLast
- FlattenDeep
- ForEach
- GroupBy
- IntSlice
- InterfaceSlice
- Intersection
- InsertByIndex
- Map
- ReverseSlice
- Reduce
- Shuffle
- SortByField
- Some
- StringSlice
- Unique
- Union
- UpdateByIndex
- Without
import "github.com/duke-git/lancet/strutil"
- After
- AfterLast
- Before
- BeforeLast
- CamelCase
- Capitalize
- IsString
- KebabCase
- LowerFirst
- UpperFirst
- PadEnd
- PadStart
- ReverseStr
- SnakeCase
- Wrap
- Unwrap
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
- IsFloatStr
- IsNumberStr
- IsJSON
- IsRegexMatch
- IsIntStr
- IsIp
- IsIpV4
- IsIpV6
- IsStrongPassword
- IsUrl
- IsWeakPassword
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.