go语言编写脚本,开源一个全面高效
一飞开源,介绍创意、新奇、有趣、实用的免费开源应用、系统、软件、硬件及技术,一个探索、发现、分享、使用与互动交流的开源技术社区平台。致力于打造活力开源社区,共建开源新生态!
一、开源项目简介
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 main
import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)
func main() {
s := "hello"
rs := strutil.ReverseStr(s)
fmt.Println(rs) //olleh
}
import "github.com/duke-git/lancet/v2/algorithm"
- BubbleSort
- CountSort
- HeapSort
- InsertionSort
- MergeSort
- QuickSort
- SelectionSort
- ShellSort
- BinarySearch
- BinaryIterativeSearch
- LinearSearch
- LRUCache
import "github.com/duke-git/lancet/v2/concurrency"
- 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"
- 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"
- 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
访问一飞开源:https://code.exmay.com/
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com