modulepackage
1.0.6
Repository: https://github.com/lulouis/marisfrolg_utils.git
Documentation: pkg.go.dev
# README
marisfrolg_utils
玛丝菲尔golang项目帮助类库
项目引用
go get github.com/lulouis/marisfrolg_utils
使用案例
帮助类分为10个部分
1、Convert
2、数据库类(DBHelper)
1、ExecuteNonQueryByTran func ExecuteNonQueryByTran(db *sql.DB, SqlList []string) error 批量执行 含事务 nil 成功 err 失败 MongoDB 禁止使用,其他数据库自行斟酌(目前支持Oracle)
测试指令: go test -v -run TestExecuteNonQueryByTran DB_test.go
参数说明:db: 数据库链接 Sql: 语句集合
2、AssemblyParameters(IdList, Field string) (condition string) SQL IN()的查询里不能超过1000列,将大于1000列的以900为间隔分开组装
测试指令: go test -v -run TestAssemblyParameters DB_test.go
参数说明:IdList:数据列 例如:"'987654321','123456789'" Field:字段名
3、GetSqlList(Parameters string, Field string) string 对数据库查询请求参数的优化
测试指令:go test -v -run TestGetSqlList DB_test.go
参数说明:Parameters:数据查询参数; Field: 字段名
4、StringToRuneArr(Parameters string) []string 对HANA查询结果的特殊符号优化
测试指令:go test -v -run TestStringToRuneArr DB_test.go
参数说明:Parameters 数据结果列请求参数
3、发送邮件相关操作(EmailHelper)
1、(emailServer EmailServer) SendMail(emailRequest EmailRequest) error 发送邮件
测试指令:go test -v -run TestSendMail Email_test.go
参数说明:emailServer:配置发件邮箱账号和密码端口号,emailRequest 配置收件人、标题、主题、正文、附加路径
4、文件相关操作(FileHelper)
1、PathlogExistsFile(path string) (bool, error)检查制定路径下是否存在文件如果不存在直接创建文件夹
测试指令:go test -v -run TestPathlogExistsFile File_test.go
参数说明:path:文件夹路径
2、CreateImg(filename string, img image.Image) error 创建图片
测试指令:go test -v -run TestCreateImg File_test.go
参数说明: filePath:文件路径
fileName:文件名称
img:图片属性
3、FileToByte(f *os.File) ([]byte,error)将文件转换成byte[]
测试指令:go test -v -run FileToByte File_test.go
参数说明:f *os.File:文件相关信息
5、Http相关操作(HttpHelper)
1、HttpPostOnlyBody(apiURL string, parmbody string, token string) (rs []byte, err error) POST请求带token验证的URL
测试指令:go test -v -run TestHttpPostOnlyBody Http_test.go
参数说明:apiURL:请求路径;parmbody:Body参数;token:需要验证的token
2、HttpGet(ApiURL string, Params url.Values) (rs []byte, err error) get请求链接接参数分离
测试指令:go test -v -run TestHttpGet Http_test.go
参数说明:ApiURL:请求路径;Parm:请求参数
3、HttpGetToUrl(ApiURL string) (rs []byte, err error) get请求链接接参数不分离
测试指令:go test -v -run TestHttpGetToUrl Http_test.go
参数说明:ApiURL:请求路径
6、文本日志相关操作类(LogUtil)
1、AddOperationLog(Type string, Title string, Message string,Filepath string) 添加操作日志
测试指令: go test -v -run TestLog Log_test.go
参数说明:Type:文件名称(可以为空) Title:函数名称 Message:要记录在日志的内容 Filepath 日志文件要存放的路径
日志格式: 日期:[2020-05-29 17:29:02] IP:169.254.126.100
标题:测试
内容:消息内容
2、PrintMyName() 获取此函数被哪一个函数调用的上一级函数名称
测试指令:go test -v -run TestPrintMyName Log_test.go
参数说明:参数无
3、GetFileName() 获取当前文件名称
测试指令:go test -v -run TestGetFileName Log_test.go
参数说明:参数无
7、Redis缓存相关操作类(RedisHelper)
8、字符串相关操作类(StringHelper)
1、PadLeft(str string, totalWidth int, paddingChar string) (r string)位数不够自动左补全
测试指令:go test -v -run TestPadLeft StringHelper_test.go
参数说明:str 传入的字符串 ,totalWidth 补的长度 ,paddingChar 补全的字符
2、PadRight(str string, totalWidth int, paddingChar string) (r string)位数不够自动右补全
测试指令:go test -v -run TestPadRight StringHelper_test.go
参数说明:str 传入的字符串 ,totalWidth 补的长度 ,paddingChar 补全的字符
3、GetRandomString(Length int) string 随机生成指定位数的大写字母
测试指令:go test -v -run TestGetRandomString StringHelper_test.go
参数说明:Length:位数
4、ValidateMobile(mobileNum string) bool 验证手机号是否符合要求
测试指令:go test -v -run TestValidateMobile StringHelper_test.go
参数说明:mobileNum:手机号码
5、RemoveRepeatedElement(arr []string) (newArr []string) 移除string数组中重复数据,返回已经处理好的无重复的string数组
测试指令:go test -v -run TestRemoveRepeatedElement StringHelper_test.go
参数说明:arr 带有重复的string数组
9、发短信相关操作类(SendMessageHelper)
1、SendShortMessage(regionId string, accessKeyId string, accessKeySecret string,PhoneNumbers string, SignName string, TemplateCode string, TemplateParam string) 阿里云发短信相关操作
测试指令:go test -v -run TestSendMessage SendMessage_test.go
参数说明:regionId:区域ID;accessKeyId:访问者身份;accessKeySecret:;SignName:加密签名字符串和服务器端验证签名字符串的密钥,必须严格保密谨防泄露;短信签名;TemplateCode:短信模板ID;TemplateParam:短信模板变量替换JSON串,友情提示:如果JSON中需要带换行符
10、时间函数相关操作类(TimeHelper)
测试案例 Usage 参考网站:http://c.biancheng.net/view/124.html
新建xxx_test.go文件 1.测试整个文件:
go test -v Convert_test.go
2.指定某个库某个方法进行测试:
go test -v -run TestPadRight StringHelper_test.go
案例1:字符串函数
package main
import (
"fmt"
"testing"
convert "github.com/lulouis/marisfrolg_utils"
)
func TestConvert(t *testing.T) {
substring := convert.Substr("marisfrolg_utils", 0, 10)
fmt.Println(substring)
}
go test -v Convert_test.go
案例2:请查看example里面的 StringHelper_test.go
运行测试案例
cd example
go test -v StringHelper_test.go
# Packages
No description provided by the author
# Functions
执行审核流程,通过、拒绝、驳回等.
添加操作日志
Type:控制器名称(可以为空)
Title:函数名称
Message:要记录在日志的内容
Filepath 日志文件要存放的路径
*/.
添加操作日志
Type:控制器名称
Title:函数名称
Message:要记录在日志的内容
*/.
SQL IN()的查询里不能超过1000列,将大于1000列的以900为间隔分开组装 IdList:数据列 例如:"'987654321','123456789'" Field:字段名.
计算公式结果.
公式检测.
创建图片 filePath :文件路径 filename:文件名称 img 图片属性.
创建.log日志.
创建流程 单据类型、用户id、姓名、工单编号.
网络文件下载.
/ <summary> / 批量执行 含事务 / </summary> / <param name="db">数据连接</param> / <param name="SqlList">Sql 列表</param> / <returns>说明:MongoDB 禁止使用,其他数据库自行斟酌(目前支持Oracle) /</returns>.
/ <summary> / 批量执行 含事务 / </summary> / <param name="db">事务化连接</param> / <param name="SqlList">语句列表</param> / <returns>说明:MongoDB 禁止使用,其他数据库自行斟酌(目前支持Oracle) /</returns>.
将文件转换成byte[].
规范化逆波兰表达式.
解析流程引擎返回代办事项.
GetDataByHanaSql 万能hana查询语句.
GetDataByMysql 2021-08-23 追加mysql万能查询 日期返回成字符串形式.
GetDataByPostgresSql 万能查询PG数据库.
GetDataByPostgresSqlByPgxPool 使用pgx连接postgresql进行连接池查询 线程安全.
GetDataBySQL 万能SQL语句查询 专门用于oracle.
调整日期加上时区.
获取当前文件名称.
No description provided by the author
从redis获取Key对应的value.
获取日期格式.
获取相差时间.
No description provided by the author
获取下一个审批节点.
随机生成指定位数的大写字母.
获取日期格式.
对数据库查询请求参数的优化 Parameters 数据查询参数 Field 字段名.
解析流程引擎数据.
获取某一天的0点时间.
获取某一天的23:59:59点时间.
get 网络请求.
No description provided by the author
post请求:只传body.
post请求:带url参数和postBodyData数据.
No description provided by the author
构建一个空栈.
是否创建目录.
判断目录是否存在.
功能:读取文件反序列化
*/.
No description provided by the author
位数不够自动左补全str 传入的字符串 ,totalWidth 补的长度 ,paddingChar 补全的字符.
位数不够自动右补全 str 传入的字符串 ,totalWidth 补的长度 ,paddingChar 补全的字符.
检查制定路径下是否存在文件如果不存在直接创建文件夹.
运算优先级别.
获取当前函数名.
移除string数组中重复数据,返回已经处理好的无重复的string数组.
No description provided by the author
将文件保存到指定目录.
发送推送消息.
发送通知给QRCODE changedType:PERMISSION_CHANGED MENU_CHANGED BADGE_CHANGED.
No description provided by the author
用于推送OC队列与OC故障.
与V2类似,大批量推送单号数组.
与V2类似,差异是一次连接,大量推送.
/ <summary> / 阿里短信发送接口 / 短信服务SDK简介 https://help.aliyun.com/document_detail/101874.html?spm=a2c4g.11186623.6.592.78ba5f30ZXZjpI / </summary> / <param name="PhoneNumbers"> / 短信接收号码,支持以逗号分隔的形式进行批量调用, / 批量上限为800个手机号码,批量调用相对于单条调用及时性稍有延迟, / 验证码类型的短信推荐使用单条调用的方式</param> / <param name="SignName">短信签名</param> / <param name="TemplateCode">短信模板ID</param> / <param name="TemplateParam"> / 可选参数, / 短信模板变量替换JSON串,友情提示:如果JSON中需要带换行符, / 请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\r\n, / 否则会导致JSON在服务端解析失败 / </param> / <returns></returns>.
使用go语言发企业微信消息.
存储值到redis.
对HANA查询结果的特殊符号优化 Parameters 数据结果列请求参数.
No description provided by the author
获取source的子串,如果start小于0或者end大于source长度则返回"" start:开始index,从0开始,包括0 end:结束index,以end结束,但不包括end.
No description provided by the author
验证手机号是否符合要求.
No description provided by the author
读取Excel文件流.
# Variables
获取国内时区.
# Structs
动作选项.
动作附加操作.
No description provided by the author
No description provided by the author
盒子,图形化对象.
No description provided by the author
定义邮箱服务器连接信息,如果是阿里邮箱 pass填密码,qq邮箱填授权码.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
审批节点.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
判断权限需要的标签类.
流程引擎.
# Interfaces
获取文件大小的接口.