主要是使用GO写的一些工具,集成了一些通用的工具包
快速开始
1、下载
go get -u -v github.com/anthony-dong/go-tool
2、使用
可以看到目前只有 upload
命令,支持全局配置--config
和 --log-level
,任何命令都通用,使用方式go-tool --config /data/config.json upload -f ./a.txt
➜ note git:(master) ✗ bin/go-tool
NAME:
go-tool - A go toll cli application for go
USAGE:
go-tool [global options] command [command options] [arguments...]
VERSION:
v1.0.0
COMMANDS:
hexo 生成hexo项目的Markdown文件
markdown 生成markdown项目的README文件
upload 文件上传工具
wrk 压测接口工具
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--config-file .go-tool.yaml set the config file .go-tool.yaml (default: "/Users/fanhaodong/.go-tool.yaml")
--log-level debug set the log level debug in "fatal|error|warn|info|debug" (default: "debug")
--help, -h show help (default: false)
--version, -v print the version (default: false)
如何贡献代码
1、所有的命令都需要实现这个接口,接口需要实现在以下位置command/{cli-command}
,可以参考:upload的实现
type Command interface {
Flag() []cli.Flag // 获取flag
InitConfig(context *cli.Context) (interface{}, error) // 获取配置信息,打印日志信息
Run(ctx context.Context) error // 允许命令
}
2、注册命令,可以在main.go 中实现
Commands: []*cli.Command{
command.NewCommand({cli-command}, {cli-desc}, {cli-pck}.NewCommand()),
},
使用Aliyun Oss上传文件,目前方便使用,且集成了Typora使用
➜ note git:(master) ✗ bin/go-tool upload --file ./About.md
2022/01/22 17:41:54.267454 api.go:63: [INFO] [upload] command load config:
{
"config-file": "/Users/xxxx/note/note/.config/.go-tool.yaml",
"decode": "uuid",
"file": "/Users/xxxx/note/note/About.md",
"log-level": "debug",
"type": "default"
}
2022/01/22 17:41:54.479533 cli.go:102: [INFO] [upload] end success, url: https://tyut.oss-accelerate.aliyuncs.com/image/2022/1-22/6ec95eb8ce0647ef8578595f3fab004d.md
Go-Wrk
压测Http接口工具
➜ go-tool git:(master) bin/go-tool wrk -h
NAME:
wrk - 压测接口工具
USAGE:
wrk [command options] [arguments...]
OPTIONS:
--duration value, -d value Set the request duration for wrk ("1ms"|"1s"|"1m"|"1h") (default: 0s)
--connections value, -c value Connections to keep open, must greater than threads (default: 12)
--threads value, -t value Number of threads to use (default: 12)
--method value, -m value Set the http request method method (default: "GET")
--url value, -u value Set the request url
--body value, -b value Set the request body
--header value, -H value Set the request header
--timeout value Socket request timeout (default: 5s)
--help, -h show help (default: false)
例如请求某个接口:
➜ go-tool git:(master) ✗ bin/go-tool wrk -t 10 -c 10 -d 10s -b hello -H content-type:application/json -u http://localhost:9999/test
[GO-TOOL] 2021/05/20 14:49:40 api.go:34: [INFO] [wrk] command load config:
{
"body": "hello",
"connections": 10,
"duration": "10s",
"header": {
"Content-Type": [
"application/json"
]
},
"method": "GET",
"threads": 10,
"timeout": "5s",
"url": "http://localhost:9999/test"
}
==========请求时长分布图==============
1ms 257038 99.74%
5ms 257681 99.99%
10ms 257704 100.00%
50ms 257709 100.00%
100ms 257709 100.00%
500ms 257709 100.00%
1000ms 257709 100.00%
5000ms 257709 100.00%
==========请求次数分布图==============
请求总次数: 257709
请求次数/s: 25770
==========请求体吞吐量==============
请求吞吐量(kb): 0kb
请求每秒吞吐量(kb/s): 0kb
程序结束,一共花费 10.001s
Go-Orm
未加入,期待
自动生成博客的README文件
➜ go-tool --config .config/go-tool.json markdown --dir /Users/fanhaodong/note/note --template .config/README-template.md
[GO-TOOL] 2021/01/26 16:29:42 api.go:34: [INFO] [markdown] command load config:
{
"config": "/Users/fanhaodong/note/note/.config/go-tool.json",
"dir": "/Users/fanhaodong/note/note",
"log-level": "debug",
"template": "/Users/fanhaodong/note/note/.config/README-template.md"
}
[GO-TOOL] 2021/01/26 16:29:42 markdown.go:72: [INFO] Get ReadmeFileInfo success, UrlPath: Not show, Total: 452
[GO-TOOL] 2021/01/26 16:29:42 markdown.go:80: [INFO] Create /Users/fanhaodong/note/note/README.md file success !!
[GO-TOOL] 2021/01/26 16:29:42 markdown.go:86: [INFO] New parser success, template file: /Users/fanhaodong/note/note/.config/README-template.md
[GO-TOOL] 2021/01/26 16:29:42 markdown.go:91: [INFO] Write README file success !!
Hexo
帮你一键生成博客项目!
➜ note git:(master) ✗ bin/go-tool hexo --dir ./ --target_dir ./hexo-home/source/_posts
2022/01/22 18:05:47.100998 api.go:63: [INFO] [hexo] command load config:
{
"config-file": "/Users/xxxx/note/note/.config/.go-tool.yaml",
"dir": "/Users/xxxx/note/note",
"ignore": [
"hexo-home"
],
"keyword": [
"xxx1x",
"xx11",
],
"log-level": "debug",
"target_dir": "/Users/xxxx/note/note/hexo-home/source/_posts"
}
2022/01/22 18:05:47.101210 run.go:107: [DEBUG] [Hexo] 开始全部的Markdown的文件, 目录: /Users/bytedance/note/note
2022/01/22 18:05:47.101641 run.go:392: [INFO] [GetAllPage] load ignore file: /Users/xxxx/note/note/.gitignore, config: [hexo-home], success!
// ...
2022/01/22 18:05:47.389879 run.go:207: [INFO] [Hexo] 操作脚本完成, 一共写入: 0, 总页数: 17
2022/01/22 18:05:47.389891 run.go:216: [INFO] [Hexo] 操作脚本完成需要删除文件: 0