• go柳叶刀工具集合


    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/lancet@v1.2.6 // 使用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

  • 相关阅读:
    「题解」洛谷 P1169 [ZJOI2007]棋盘制作
    「题解」洛谷 P4147 玉蟾宫
    dsu on tree 学习笔记
    [USACO08FEB]Hotel G「线段树」
    城市环路「树形DP」
    Siano「线段树」
    Emiya 家今天的饭「容斥+DP」
    Matlab调用其他文件夹下的函数
    基于小波金字塔的简单图像融合算法matlab实现
    知网引文网络使用方法
  • 原文地址:https://www.cnblogs.com/cheyunhua/p/16820428.html
Copyright © 2020-2023  润新知