Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js.
English | 简体中文
Feature
- 👏 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.
Installation
go get github.com/duke-git/lancet
Usage
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"
Example
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
}
API Documentation
Convertor package contains some functions for data convertion.
import "github.com/duke-git/lancet/convertor"
Function list:
Cryptor package is for data encryption and decryption.
import "github.com/duke-git/lancet/cryptor"
Function list:
- 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
Datetime package supports date and time format and compare.
import "github.com/duke-git/lancet/datetime"
Function list:
- AddDay
- AddHour
- AddMinute
- BeginOfMinute
- BeginOfHour
- BeginOfDay
- BeginOfWeek
- BeginOfMonth
- BeginOfYear
- EndOfMinute
- EndOfHour
- EndOfDay
- EndOfWeek
- EndOfMonth
- EndOfYear
- GetNowDate
- GetNowTime
- GetNowDateTime
- GetZeroHourTimestamp
- GetNightTimestamp
- FormatTimeToStr
- FormatStrToTime
Fileutil package implements some basic functions for file operations.
import "github.com/duke-git/lancet/fileutil"
Function list:
- ClearFile
- CreateFile
- CopyFile
- FileMode
- MiMeType
- IsExist
- IsLink
- IsDir
- ListFileNames
- RemoveFile
- ReadFileToString
- ReadFileByLine
- Zip
- UnZip
Formatter contains some functions for data formatting.
import "github.com/duke-git/lancet/formatter"
Function list:
Function package can control the flow of function execution and support part of functional programming
import "github.com/duke-git/lancet/function"
Function list:
Netutil package contains functions to get net information and send http request.
import "github.com/duke-git/lancet/netutil"
Function list:
- ConvertMapToQueryString
- GetInternalIp
- GetIps
- GetMacAddrs
- GetPublicIpInfo
- IsPublicIP
- HttpGet
- HttpDelete
- HttpPost
- HttpPut
- HttpPatch
- ParseHttpResponse
Random package implements some basic functions to generate random int and string.
import "github.com/duke-git/lancet/random"
Function list:
Retry package is for executing a function repeatedly until it was successful or canceled by the context.
import "github.com/duke-git/lancet/retry"
Function list:
Slice contains some functions to manipulate slice.
import "github.com/duke-git/lancet/slice"
Function list:
- 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
Strutil package contains some functions to manipulate string.
import "github.com/duke-git/lancet/strutil"
Function list:
- After
- AfterLast
- Before
- BeforeLast
- CamelCase
- Capitalize
- IsString
- KebabCase
- LowerFirst
- UpperFirst
- PadEnd
- PadStart
- ReverseStr
- SnakeCase
- Wrap
- Unwrap
System package contain some functions about os, runtime, shell command.
import "github.com/duke-git/lancet/system"
Function list:
Validator package contains some functions for data validation.
import "github.com/duke-git/lancet/validator"