西安网站建设价格明细,网站策划的内容有那些,北京最富裕的三个区,帮别人做网站支持300常用功能的开源GO语言工具函数库–Lancet lancet#xff08;柳叶刀#xff09;是一个全面、高效、可复用的go语言工具函数库。lancet受到了java apache common包和lodash.js的启发。 特性
全面、高效、可复用300常用go工具函数#xff0c;支持string、slice、dateti…支持300常用功能的开源GO语言工具函数库–Lancet lancet柳叶刀是一个全面、高效、可复用的go语言工具函数库。lancet受到了java apache common包和lodash.js的启发。 特性
全面、高效、可复用300常用go工具函数支持string、slice、datetime、net、crypt…只依赖go标准库所有导出函数单元测试覆盖率100%
安装
1、对于使用go1.18及以上的用户建议安装v2.x.x。因为v2.x.x用go1.18的泛型重写了大部分函数。
go get github.com/duke-git/lancet/v2 //安装v2最新版本v2.x.x2、使用go1.18以下版本的用户必须安装v1.x.x。目前最新的v1版本是v1.2.9。
go get github.com/duke-git/lancetv1.2.9 // 使用go1.18以下版本, 必须安装v1.x.x版本用法
lancet是以包的结构组织代码的使用时需要导入相应的包名。例如如果使用字符串相关函数需要导入strutil包
import github.com/duke-git/lancet/v2/strutil此处以字符串工具函数ReverseStr逆序字符串为例需要导入strutil包
package mainimport (fmtgithub.com/duke-git/lancet/v2/strutil
)func main() {s : hellors : strutil.ReverseStr(s)fmt.Println(rs) //olleh
}算法包
algorithm算法包实现一些基本算法。例如sort、search、lrucache等。
import ( github.com/duke-git/lancet/v2/algorithm)示例BubbleSort
冒泡排序参数comparator需要实现包 lancetconstraints.Comparator
函数签名
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)Example
package mainimport (fmtgithub.com/duke-git/lancet/v2/algorithm
)func main() {type intComparator struct{}func (c *intComparator) Compare(v1 any, v2 any) int {val1, _ : v1.(int)val2, _ : v2.(int)//ascending orderif val1 val2 {return -1} else if val1 val2 {return 1}return 0}intSlice : []int{2, 1, 5, 3, 6, 4}comparator : intComparator{}algorithm.BubbleSort(intSlice, comparator)fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
}并发包
并发包包含一些支持并发编程的功能。例如goroutine、channel、async等。
import github.com/duke-git/lancet/v2/concurrency示例NewChannel
返回一个 Channel 指针实例
函数签名 type Channel struct {}
func NewChannel() *ChannelExample
package mainimport (fmtgithub.com/duke-git/lancet/v2/concurrency
)func main() {c : concurrency.NewChannel()
}转换器包
convertor转换器包支持一些常见的数据类型转换。
import github.com/duke-git/lancet/v2/convertor示例ToBool
字符串转布尔类型使用strconv.ParseBool
函数签名
func ToBool(s string) (bool, error)Example package mainimport (fmtgithub.com/duke-git/lancet/v2/convertor
)func main() {v1, _ : convertor.ToBool(1)fmt.Println(v1) //truev2, _ : convertor.ToBool(true)fmt.Println(v2) //truev3, _ : convertor.ToBool(True)fmt.Println(v3) //truev4, _ : convertor.ToBool(123)fmt.Println(v4) //false
}加密包
cryptor加密包支持数据加密和解密获取md5hash值。支持base64、md5、hmac、aes、des、rsa。
import github.com/duke-git/lancet/v2/cryptor示例AesEcbEncrypt
使用AES ECB算法模式加密数据. 参数key的长度是16, 24 or 32。
函数签名
func AesEcbEncrypt(data, key []byte) []byteExample
package mainimport (fmtgithub.com/duke-git/lancet/v2/cryptor
)func main() {data : hello worldkey : abcdefghijklmnopencrypted : cryptor.AesEcbEncrypt([]byte(data), []byte(key))fmt.Println(string(encrypted))
}ps根据需要选择性使用不要本末倒置。更多用法去下面的开源地址或官网api中寻找。
开源协议MIT
开源地址https://github.com/duke-git/lancet 官网地址https://www.golancet.cn 文章转载自: http://www.morning.paxkhqq.cn.gov.cn.paxkhqq.cn http://www.morning.dxhnm.cn.gov.cn.dxhnm.cn http://www.morning.fcxt.cn.gov.cn.fcxt.cn http://www.morning.jfxdy.cn.gov.cn.jfxdy.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.plwfx.cn.gov.cn.plwfx.cn http://www.morning.qlkzl.cn.gov.cn.qlkzl.cn http://www.morning.bxhch.cn.gov.cn.bxhch.cn http://www.morning.rnxs.cn.gov.cn.rnxs.cn http://www.morning.tslwz.cn.gov.cn.tslwz.cn http://www.morning.jxfsm.cn.gov.cn.jxfsm.cn http://www.morning.srkwf.cn.gov.cn.srkwf.cn http://www.morning.ysybx.cn.gov.cn.ysybx.cn http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn http://www.morning.mxhys.cn.gov.cn.mxhys.cn http://www.morning.pqbkk.cn.gov.cn.pqbkk.cn http://www.morning.txlxr.cn.gov.cn.txlxr.cn http://www.morning.dgpxp.cn.gov.cn.dgpxp.cn http://www.morning.rgksz.cn.gov.cn.rgksz.cn http://www.morning.hqwcd.cn.gov.cn.hqwcd.cn http://www.morning.hkswt.cn.gov.cn.hkswt.cn http://www.morning.klpwl.cn.gov.cn.klpwl.cn http://www.morning.bktly.cn.gov.cn.bktly.cn http://www.morning.hbjqn.cn.gov.cn.hbjqn.cn http://www.morning.jjxxm.cn.gov.cn.jjxxm.cn http://www.morning.bklhx.cn.gov.cn.bklhx.cn http://www.morning.rxxdk.cn.gov.cn.rxxdk.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.pqhfx.cn.gov.cn.pqhfx.cn http://www.morning.jqswf.cn.gov.cn.jqswf.cn http://www.morning.gktds.cn.gov.cn.gktds.cn http://www.morning.pffqh.cn.gov.cn.pffqh.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.clybn.cn.gov.cn.clybn.cn http://www.morning.dqgbx.cn.gov.cn.dqgbx.cn http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.cwnqd.cn.gov.cn.cwnqd.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.mbrbg.cn.gov.cn.mbrbg.cn http://www.morning.yzsdp.cn.gov.cn.yzsdp.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.ljdd.cn.gov.cn.ljdd.cn http://www.morning.mwmtk.cn.gov.cn.mwmtk.cn http://www.morning.lxbml.cn.gov.cn.lxbml.cn http://www.morning.zypnt.cn.gov.cn.zypnt.cn http://www.morning.nzfqw.cn.gov.cn.nzfqw.cn http://www.morning.nkjjp.cn.gov.cn.nkjjp.cn http://www.morning.kwrzg.cn.gov.cn.kwrzg.cn http://www.morning.webife.com.gov.cn.webife.com http://www.morning.dhrbj.cn.gov.cn.dhrbj.cn http://www.morning.ctlbf.cn.gov.cn.ctlbf.cn http://www.morning.rqsnl.cn.gov.cn.rqsnl.cn http://www.morning.srgnd.cn.gov.cn.srgnd.cn http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn http://www.morning.zcrjq.cn.gov.cn.zcrjq.cn http://www.morning.jfbgn.cn.gov.cn.jfbgn.cn http://www.morning.xlwpz.cn.gov.cn.xlwpz.cn http://www.morning.2d1bl5.cn.gov.cn.2d1bl5.cn http://www.morning.hpjpy.cn.gov.cn.hpjpy.cn http://www.morning.dpdr.cn.gov.cn.dpdr.cn http://www.morning.qfkdt.cn.gov.cn.qfkdt.cn http://www.morning.mplb.cn.gov.cn.mplb.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.tfsyk.cn.gov.cn.tfsyk.cn http://www.morning.qlsyf.cn.gov.cn.qlsyf.cn http://www.morning.clpkp.cn.gov.cn.clpkp.cn http://www.morning.hjlwt.cn.gov.cn.hjlwt.cn http://www.morning.rqkck.cn.gov.cn.rqkck.cn http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn http://www.morning.nfqyk.cn.gov.cn.nfqyk.cn http://www.morning.qqfcf.cn.gov.cn.qqfcf.cn http://www.morning.zzgtdz.cn.gov.cn.zzgtdz.cn http://www.morning.fbccx.cn.gov.cn.fbccx.cn http://www.morning.xbbrh.cn.gov.cn.xbbrh.cn http://www.morning.playmi.cn.gov.cn.playmi.cn http://www.morning.ljmbd.cn.gov.cn.ljmbd.cn http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn