官网文档地址->:文档地址

一、概述

ZTool是在上个gotool的根底上延长过去的,因为gotoo这个我的项目两头存在很多第三方库的依赖,然而第三方库进行更新,两头存在很多bug没有保护,造成工具包两头同样存在很多问题
最终通过思考,进行保护gotool从新开一个工程,ztool不进行任何的第三方库依赖,进行开发。同时通过两年多的理论我的项目开发总结,将业务底层代码抽离,抽出了由,字符串、工夫、随机id、http客户端、加密等工具集,同时咱们也欢送宽广go爱好者进行pr,同时咱们也开拓了pr通道

二、简介

ZTool是一个玲珑而快捷工具库,通过办法封装,升高相干API的学习老本,进步工作效率,让应用GO语言开发编写代码更加优雅。

ZTool中的工具办法来自咱们长达两年的多应用go语言进行理论我的项目开发总结而来,它涵盖了GO开发中罕用的办法,它既是大型项目开发中解决小问题的利器,也是小型我的项目中的效率担当;

ZTool它节俭了开发人员对我的项目中专用类和专用工具办法的封装工夫,使开发专一于业务,同时能够最大限度的防止封装不欠缺带来的bug。

三、装置

  1. go开发环境装置
  • 安装包下载地址:官网地址:https://go.dev/dl/
  • 如果无奈关上请应用备选地址:备选地址:https://go.dev/dl/
  1. go env来查看和验证go的环境信息,例如我的局部配置信息如下:
GO111MODULE="on"GOARCH="amd64"GOBIN=""GOCACHE="/Users/Janus/Library/Caches/go-build"GOENV="/Users/Janus/Library/Application Support/go/env"GOMODCACHE="/Users/Janus/gopath/pkg/mod"GONOPROXY="github.com"GONOSUMDB="github.com"GOPATH="/Users/Janus/gopath"GOPRIVATE="github.com"GOPROXY="https://goproxy.cn,direct"GOROOT="/usr/local/go"GOSUMDB="sum.golang.org"GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"

<font color="red">留神:GO111MODULE必须是开启开启状态,若为开启请自行google或百度解决</font>

2、ztool工具包装置

  1. 版本要求
go >=1.15 
  1. 版本查看
go version 
  1. go get 装置
go get -u -b github.com/druidcaesa/ztool
  1. go mod装置
require github.com/druidcaesa/ztool

四、字符串操作工具

<font size="3">应用<font color="red"> ztool.StrUtils</font>调用对应的办法,ztool.StrUtils是字符串操作的外围类</font>

办法参数阐明阐明
SnakeStringstring驼峰转蛇形,返回类型为string
CamelStringstring蛇形转驼峰,返回类型为string
HasBlankstring不可见字符串判空,返回bool类型
HasEmptystring判断是否是空字符串(""),返回bool类型
RemoveSuffixstring删除文件后缀获取文件名,返回string
RemovePrefixstring获取文件拓展名,返回string
EncodeHexStringstring字符串16进制编码,返回string
DecodeHexStringstring16进制转字符串,返回(string,error)

五、工夫操作工具

<font size="3">应用<font color="red"> ztool.DateUtils</font>调用对应的办法,ztool.DateUtils是工夫用用的外围类</font>

ztool.DateUtils的返回类型是个struct以下是对构造体的阐明,ztool.DateUtils可应用链式办法调用

type DateTime struct {    t            time.Time //go的工夫类型封装    weekStartDay common.Weekday //一周的开始工夫设定}
办法参数阐明阐明
Now无参获取以后工夫,返回类型为DateTime构造体
Format...string可选参数格式化工夫,返回类型是string 字符串
SetTime...time.Time可选工夫类型参数设置工夫,须要传入time.Time,返回类型为DateTime构造体
OperationDayint 参数为int依照天对工夫进行加减,参数可正负,返回类型为DateTime构造体
OperationMoonint 参数为int依照月对工夫进行加减,参数可正负,返回类型为DateTime构造体
OperationYearsint 参数为int依照年对工夫进行加减,参数可正负,返回类型为DateTime构造体
StartOfHour无参获取以后工夫的开始工夫,返回类型为DateTime构造体
StartTimeOfDay无参获取当天的开工夫,返回类型为DateTime构造体
StartOfMinute无参获取分钟的开始,返回类型为DateTime构造体
StartOfWeek无参获取一周的开工夫,返回类型为DateTime构造体
StartOfMonth无参获取当月的开始工夫 ,返回类型为DateTime构造体
SetWeekStartDaycommon.Monday设置一周的开始工夫是那天 ,返回类型为DateTime构造体
StartOfQuarter无参获取以后季度的开始工夫 ,返回类型为DateTime构造体
StartOfYear无参获取本年度开始工夫 ,返回类型为DateTime构造体
EndOfMinute无参获取以后分钟完结工夫 ,返回类型为DateTime构造体
EndOfHour无参获取以后小时的完结工夫 ,返回类型为DateTime构造体
EndOfDay无参获取明天的完结工夫 ,返回类型为DateTime构造体
EndOfWeek无参获取本周完结工夫 ,返回类型为DateTime构造体
EndOfMonth无参获取本月完结工夫 ,返回类型为DateTime构造体
EndOfQuarter无参获取本季度完结工夫 ,返回类型为DateTime构造体
EndOfYear无参获取本年度完结工夫 ,返回类型为DateTime构造体
Parse...string字符串格式化工夫 ,返回类型为DateTime构造体

六、加密操作工具

<font size="3">应用<font color="red"> ztool.EncryptionUtils</font>调用对应的办法,ztool.EncryptionUtils是加密工具的外围类</font>

办法参数阐明阐明
AesEncryptstring,...stringAES加密办法,返回类型为(string,error)
AesDecryptstring,...stringAES解密办法,返回类型为(string,error)
DesDecryptstring,...stringDES解密办法,返回类型为(string,error)
DesDecryptstring,...stringDES解密办法,返回类型为(string,error)
Md5EncodestringMd5签名办法,返回类型为string
Md5Checkstring,stringMd5Check,返回类型为boole

七、Http客户端

<font size="3">应用<font color="red"> ztool.HttpUtils</font>调用对应的办法,ztool.HttpUtils是http客户端工具的外围类</font>

办法参数阐明阐明
Getstring,...interface{}发送GET申请,返回类型为(string, error)
Poststring,...interface{}发送POST申请,返回类型为(string, error)
Putstring,...interface{}发送PUT申请,返回类型为(string, error)
Deletestring,...interface{}发送DELETE申请,返回类型为(string, error)
UploadFilePathurl, filename, filePath string文件上传,返回类型为(string, error)
NewRequest无参获取request,返回类型为request 构造体
  • request构造体是自定义构造体,外面有原http的request的对应封装
// Request request subjecttype Request struct {    //request client    cli *http.Client    //Timeout setting    timeout time.Duration    //request handler    headers map[string]string    //request parameters    data interface{}    //logger turn on    logger bool    //specifies the cookie  jar    jar http.CookieJar    //For details of the agent, please refer to the official documentation    proxy func(*http.Request) (*url.URL, error)    //CheckRedirect specifies the policy for handling redirects    checkRedirect func(req *http.Request, via []*http.Request) error    //cookies setting    cookies map[string]string    //set request method    method string    //set request url    url              string    tlsClientConfig  *tls.Config    disableKeepAlive bool    transport        *http.Transport    debug            bool}

八、加密工具

<font size="3">应用<font color="red"> ztool.IdUtils</font>调用对应的办法,ztool.IdUtils是ID生成工具的外围类</font>

办法参数阐明阐明
RandomUUID无参带有"-"的UUID,返回类型为(string,error)
SimpleUUID无参不带"-"的UUID,返回类型为(string,error)
GenerateSnowflakeId无参SnowFlake算法的ID,返回类型为int

九、身份验证

<font size="3">应用<font color="red"> ztool.IDCardUtils</font>,当初反对大陆15位、18位身份证</font>

办法参数阐明阐明
Checkstring全局校验身份证,返回类型为(bool, error)
GetProvinceByIdCardstring获取身份证所在地,string
IsValidCardstring身份证是否合乎18或者15位,返回类型为(bool, error)
Convert15To18string15位转18位,返回类型为string
GetBirthByIdCardstring获取生日,返回类型为(string, error)
GetAgeByIdCardstring获取年龄,返回类型为int
GetYearByIdCardstring获取出世年,返回类型为string
GetMonthByIdCardstring获取出世月,返回类型为string
GetDayByIdCardstring获取出世日,返回类型为string
GetSexstring获取性别,返回类型为int