首页 > 其他分享 >go柳叶刀工具集合

go柳叶刀工具集合

时间:2022-10-24 09:33:10浏览次数:48  
标签:duke git 柳叶刀 集合 v2 github go com lancet

lancet 是一个全面、高效、可复用的go语言工具函数库。 本次发布v2.0.0版本,全面升级go1.18,应用泛型重写大部分函数。同时新增70+函数。

特性
全面、高效、可复用
250+常用go工具函数,支持string、slice、datetime、net、crypt…
只依赖go标准库
所有导出函数单元测试覆盖率100%
安装
Note:
对于使用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.6。
go get github.com/duke-git/[email protected] // 使用go1.18以下版本, 必须安装v1.x.x版本

用法
lancet是以包的结构组织代码的,使用时需要导入相应的包名。例如:如果使用字符串相关函数,需要导入strutil包:

import "github.com/duke-git/lancet/v2/strutil"

例子
此处以字符串工具函数ReverseStr(逆序字符串)为例,需要导入strutil包:

package main

import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)

func main() {
s := "hello"
rs := strutil.ReverseStr(s)
fmt.Println(rs) //olleh
}

API文档
algorithm算法包实现一些基本算法。eg. sort, search.
import "github.com/duke-git/lancet/v2/algorithm"
1
Function list:
BubbleSort
CountSort
HeapSort
InsertionSort
MergeSort
QuickSort
SelectionSort
ShellSort
BinarySearch
BinaryIterativeSearch
LinearSearch
LRUCache
convertor转换器包支持一些常见的数据类型转换。
import "github.com/duke-git/lancet/v2/convertor"

函数列表:
ColorHexToRGB
ColorRGBToHex
ToBool
ToBytes
ToChar
ToInt
ToJson
ToString
StructToMap
cryptor加密包支持数据加密和解密,获取md5,hash值。支持base64, md5, hmac, aes, des, rsa。
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
datetime日期时间处理包,格式化日期,比较日期。
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
fileutil包支持文件基本操作。
import "github.com/duke-git/lancet/v2/fileutil"

函数列表:
ClearFile
CreateFile
CopyFile
FileMode
MiMeType
IsExist
IsLink
IsDir
ListFileNames
RemoveFile
ReadFileToString
ReadFileByLine
Zip
UnZip
formatter格式化器包含一些数据格式化处理方法。
import "github.com/duke-git/lancet/v2/formatter"

函数列表:
Comma
function函数包控制函数执行流程,包含部分函数式编程。
import "github.com/duke-git/lancet/v2/function"

函数列表:
After
Before
Curry
Compose
Debounced
Delay
Watcher
mathutil包实现了一些数学计算的函数。
import "github.com/duke-git/lancet/v2/mathutil"

Function list:
Exponent
Fibonacci
Factorial
Percent
RoundToFloat
RoundToString
TruncRound
netutil网络包支持获取ip地址,发送http请求。
import "github.com/duke-git/lancet/v2/netutil"

函数列表:
ConvertMapToQueryString
GetInternalIp
GetIps
GetMacAddrs
GetPublicIpInfo
IsPublicIP
HttpGet
HttpDelete
HttpPost
HttpPut
HttpPatch
ParseHttpResponse
random随机数生成器包,可以生成随机[]bytes, int, string。
import "github.com/duke-git/lancet/v2/random"

函数列表:
RandBytes
RandInt
RandString
UUIdV4
retry重试执行函数直到函数运行成功或被context cancel。
import "github.com/duke-git/lancet/v2/retry"
1
函数列表:
Context
Retry
RetryFunc
RetryDuration
RetryTimes
slice包包含操作切片的方法集合。
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
IntSlice
InterfaceSlice
Intersection
InsertAt
Map
Reverse
Reduce
Shuffle
SortByField
Some
StringSlice
Unique
Union
UpdateAt
Without
strutil包含处理字符串的相关函数。
import "github.com/duke-git/lancet/v2/strutil"

函数列表:
After
AfterLast
Before
BeforeLast
CamelCase
Capitalize
IsString
KebabCase
LowerFirst
UpperFirst
PadEnd
PadStart
ReverseStr
SnakeCase
Wrap
Unwrap
system包含os, runtime, shell command相关函数。
import "github.com/duke-git/lancet/v2/system"

函数列表:
IsWindows
IsLinux
IsMac
GetOsEnv
SetOsEnv
RemoveOsEnv
CompareOsEnv
ExecCommand
validator验证器包,包含常用字符串格式验证函数。
import "github.com/duke-git/lancet/v2/validator"
1
函数列表:
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)

xerror包实现一些错误处理函数
import "github.com/duke-git/lancet/v2/xerror"

函数列表:
Unwrap
如何贡献代码
非常感激任何的代码提交以使lancet的功能越来越强大。创建pull request时请遵守以下规则。

Fork lancet仓库。
创建自己的特性分支。
提交变更。
Push分支。
创建新的pull request。
————————————————
版权声明:本文为CSDN博主「weixin_41155794」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_41155794/article/details/123549299

标签:duke,git,柳叶刀,集合,v2,github,go,com,lancet
From: https://www.cnblogs.com/cheyunhua/p/16820428.html

相关文章

  • 给 hugo 博客添加搜索功能
    起因我的博客使用了hugo作为静态生成工具,自带的主题里也没有附带搜索功能。看来,还是得自己给博客添加一个搜索功能。经过多方查找,从HugoFastSearch·GitHub找到......
  • Go 语言 errgroup 库的使用方式和实现原理
    大家好,我是frank。欢迎大家点击标题下方蓝色文字「Golang语言开发栈」关注公众号。设为星标,第一时间接收推送文章。文末扫码,加群一起学Golang语言。01 介绍在Go......
  • 【Golang】通过Go Ballast 控制内存来优化性能
    一、关于GoGC优化的手段设置GOGC /debug.SetGCPercent()这两种方式的原理和效果都是一样的,GOGC默认值是100,也就是下次GC触发的heap的大小是这次GC之后的......
  • django中APIView里的dispatch和as_view方法分析
    位置:fromrest_framework.viewsimportAPIView继承APIView类视图形式的路由:path('booksapiview/',views.BooksAPIView.as_view()),#在这个地方应该写个函数内存地址......
  • RuntimeError: Deterministic behavior was enabled with either `torch.use_determin
    在CORL的代码中,出现了一种error:  可经过如下方法解决:cuda10.1os.environ['CUDA_LAUNCH_BLOCKING']='1'cuda10.2及以上os.environ['CUBLAS_WORKSPACE_CONFIG']......
  • 论 C++、C、Go 和 Java 的最大不同
     一、C++、C、Go中的如下语句:structxxx s1;vector<int>v;(甚至会调构造函数!)varABCsomeType其实会创建一个能用的对象!!、之后用他们进行操作......
  • golang中的nil接收器
    索引:https://waterflow.link/articles/1666534616841我们先看一个简单的例子,我们自定义一个错误,用来把多个错误放在一起输出:typeCustomErrorstruct{ errors[]string......
  • golang postman workspaces(api)
    获取所有workspacespackagemainimport("fmt""net/http""io/ioutil")funcmain(){url:="https://api.getpostman.com/workspaces"method:="GET"client:......
  • ubuntu+Django + nginx + uwsgi 部署
    ubuntu+Django+nginx+uwsgi部署0.前期准备注意:以下几件事都必须在激活虚拟环境下完成运行以下命令生成项目所需的依赖列表,会在项目根目录生成一个requirements.......
  • 使用GoLang新建一个Go web file 文件服务
    packagemainimport( "github.com/gin-gonic/gin" "github.com/satori/go.uuid" "io" "net/http" "os" "path")const( //最大上传100M SR_File_Max_Bytes......