4

lancet(go语言工具函数库)发布v2.0.0, 全面支持go泛型特性

 2 years ago
source link: https://studygolang.com/articles/35537
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

lancet(go语言工具函数库)发布v2.0.0, 全面支持go泛型特性

duke-git · 5天之前 · 411 次点击 · 预计阅读时间 25 分钟 · 大约8小时之前 开始浏览    

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"

Function list:

convertor转换器包支持一些常见的数据类型转换。

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

函数列表:

cryptor加密包支持数据加密和解密,获取md5,hash值。支持base64, md5, hmac, aes, des, rsa。

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

函数列表:

datetime日期时间处理包,格式化日期,比较日期。

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

函数列表:

fileutil包支持文件基本操作。

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

函数列表:

formatter格式化器包含一些数据格式化处理方法。

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

函数列表:

function函数包控制函数执行流程,包含部分函数式编程。

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

函数列表:

mathutil包实现了一些数学计算的函数。

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

Function list:

netutil网络包支持获取ip地址,发送http请求。

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

函数列表:

random随机数生成器包,可以生成随机[]bytes, int, string。

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

函数列表:

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

函数列表:

slice包包含操作切片的方法集合。

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

函数列表:

strutil包含处理字符串的相关函数。

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

函数列表:

system包含os, runtime, shell command相关函数。

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

函数列表:

validator验证器包,包含常用字符串格式验证函数。

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

函数列表:

validator.md#IsWeakPassword)

xerror包实现一些错误处理函数

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

函数列表:

如何贡献代码

非常感激任何的代码提交以使lancet的功能越来越强大。创建pull request时请遵守以下规则。

  1. Fork lancet仓库。
  2. 创建自己的特性分支。
  3. 提交变更。
  4. Push分支。
  5. 创建新的pull request。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK