2022-06-09 23:52 发表于湖南
一、开源项目简介一飞开源,介绍创意、新奇、有趣、实用的免费开源应用、系统、软件、硬件及技术,一个探索、发现、分享、使用与互动交流的开源技术社区平台。致力于打造活力开源社区,共建开源新生态!
lancet(柳叶刀)是一个全面、高效、可复用的go语言工具函数库。lancet受到了java apache common包和lodash.js的启发。
二、开源协议使用MIT开源协议
三、界面展示四、功能概述特性全面、高效、可复用
300+常用go工具函数,支持string、slice、datetime、net、crypt...
只依赖go标准库
所有导出函数单元测试覆盖率100%
对于使用go1.18及以上的用户,建议安装v2.x.x。因为v2.x.x用go1.18的泛型重写了大部分函数。
go get github.com/duke-git/lancet/v2 //安装v2最新版本v2.x.x
使用go1.18以下版本的用户,必须安装v1.x.x。目前最新的v1版本是v1.2.9。
go get github.com/duke-git/lancet@v1.2.9 // 使用go1.18以下版本, 必须安装v1.x.x版本用法
lancet是以包的结构组织代码的,使用时需要导入相应的包名。例如:如果使用字符串相关函数,需要导入strutil包:
import "github.com/duke-git/lancet/v2/strutil"例子
此处以字符串工具函数ReverseStr(逆序字符串)为例,需要导入strutil包:
package mainimport ( "fmt"
"github.com/duke-git/lancet/v2/strutil")func main() {
s := "hello"
rs := strutil.ReverseStr(s)
fmt.Println(rs) //olleh}
API文档1. algorithm算法包实现一些基本算法。eg. sort, search.import "github.com/duke-git/lancet/v2/algorithm"Function list:
BubbleSort
CountSort
HeapSort
InsertionSort
MergeSort
QuickSort
SelectionSort
ShellSort
BinarySearch
BinaryIterativeSearch
LinearSearch
LRUCache
import "github.com/duke-git/lancet/v2/concurrency"Function list:
NewChannel
Bridge
FanIn
Generate
Or
OrDone
Repeat
RepeatFn
Take
Tee
import "github.com/duke-git/lancet/v2/convertor"函数列表:
ColorHexToRGB
ColorRGBToHex
ToBool
ToBytes
ToChar
ToInt
ToJson
ToString
StructToMap
import "github.com/duke-git/lancet/v2/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/v2/datetime"函数列表:
AddDay
AddHour
AddMinute
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
import list "github.com/duke-git/lancet/v2/datastructure/list"import link "github.com/duke-git/lancet/v2/datastructure/link"import stack "github.com/duke-git/lancet/v2/datastructure/stack"import queue "github.com/duke-git/lancet/v2/datastructure/queue"import set "github.com/duke-git/lancet/v2/datastructure/set"import tree "github.com/duke-git/lancet/v2/datastructure/tree"Function list:
List
Linklist
Stack
Queue
Set
Tree
import "github.com/duke-git/lancet/v2/fileutil"函数列表:
ClearFile
CreateFile
CopyFile
FileMode
MiMeType
IsExist
IsLink
IsDir
ListFileNames
RemoveFile
ReadFileToString
ReadFileByLine
Zip
UnZip
import "github.com/duke-git/lancet/v2/formatter"函数列表:
Comma
import "github.com/duke-git/lancet/v2/function"函数列表:
After
Before
Curry
Compose
Debounced
Delay
Watcher
import "github.com/duke-git/lancet/v2/maputil"函数列表:
ForEach
Filter
Intersect
Keys
Merge
Minus
Values
import "github.com/duke-git/lancet/v2/mathutil"Function list:
Average
Exponent
Fibonacci
Factorial
Max
MaxBy
Min
MinBy
Percent
RoundToFloat
RoundToString
TruncRound
import "github.com/duke-git/lancet/v2/netutil"函数列表:
ConvertMapToQueryString
GetInternalIp
GetIps
GetMacAddrs
GetPublicIpInfo
IsPublicIP
HttpGet
HttpDelete
HttpPost
HttpPut
HttpPatch
ParseHttpResponse
import "github.com/duke-git/lancet/v2/random"函数列表:
RandBytes
RandInt
RandString
UUIdV4
import "github.com/duke-git/lancet/v2/retry"函数列表:
Context
Retry
RetryFunc
RetryDuration
RetryTimes
import "github.com/duke-git/lancet/v2/slice"函数列表:
Contain
ContainSubSlice
Chunk
Compact
Concat
Count
Difference
DifferenceBy
DifferenceWith
DeleteAt
Drop
Every
Filter
Find
FindLast
FlattenDeep
ForEach
GroupBy
GroupWith
IntSlice
InterfaceSlice
Intersection
InsertAt
IndexOf
LastIndexOf
Map
Reverse
Reduce
Shuffle
SortByField
Some
StringSlice
SymmetricDifference
Unique
Union
UpdateAt
Without
import "github.com/duke-git/lancet/v2/strutil"函数列表:
After
AfterLast
Before
BeforeLast
CamelCase
Capitalize
IsString
KebabCase
LowerFirst
UpperFirst
PadEnd
PadStart
ReverseStr
SnakeCase
SplitEx
Wrap
Unwrap
import "github.com/duke-git/lancet/v2/system"函数列表:
IsWindows
IsLinux
IsMac
GetOsEnv
SetOsEnv
RemoveOsEnv
CompareOsEnv
ExecCommand
import "github.com/duke-git/lancet/v2/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
validator.md#IsWeakPassword)
19. xerror包实现一些错误处理函数import "github.com/duke-git/lancet/v2/xerror"函数列表:
Unwrap
访问一飞开源:/