https://github.com/520mianxiangduixiang520/gotools
使用 Go 时积累的一些小工具
https://github.com/520mianxiangduixiang520/gotools
go godoc golang tools
Last synced: 3 months ago
JSON representation
使用 Go 时积累的一些小工具
- Host: GitHub
- URL: https://github.com/520mianxiangduixiang520/gotools
- Owner: 520MianXiangDuiXiang520
- License: mit
- Created: 2020-10-19T02:37:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-01T13:22:12.000Z (over 4 years ago)
- Last Synced: 2025-01-17T00:47:18.438Z (5 months ago)
- Topics: go, godoc, golang, tools
- Language: Go
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GoTools
[](https://pkg.go.dev/github.com/520MianXiangDuiXiang520/GoTools)
包含一些平时 Go 开发过程中积累的小工具。
使用:```go
go get github.com/520MianXiangDuiXiang520/GoTools
```## CheckTools
这是一个通过结构体标签快速检查值是否合法的工具,可以为结构体字段添加 `check` 标签,并使用 `Check()` 函数检查,目前支持以下标签:
`int, int8, int16, int32, int64`:
| 标签示例 | 作用 |
| ------------------------ | ------------------------------- |
| `not null` 或 `not zero` | 非零判断 |
| `size: [0, 10]` | 判断范围在 0 到 10 之间,开区间 |
| `more: 10` | 判断值大于10 |
| `less: 10` | 判断值小于 10 |
| `equal: 10` | 判断值等于 10 |`string`:
| 标签示例 | 作用 |
| -------------- | ----------------------------------- |
| `not null` | 不为空 |
| `len: [2, 10]` | 字符串长度在 2 到 10 之间(闭区间) |
| `email` | 判断是否是一个电子邮件 |* **注意**:len 判断的是字符串底层字符数组的长度,对于中文或其他语言可能产生意外
`slice`:
| 标签示例 | 作用 |
| -------------- | --------------------------------- |
| `len: [2, 10]` | 元素长度在 2 到 10 之间(开区间) |`ptr`:
| 标签示例 | 作用 |
| ----------------------- | ---------------- |
| `not null` 或 `not nil` | 判断是否为空指针 |`struct`:
如果一个 struct 包含另一个 struct, 则允许递归判断, 具体用法请参考 [godoc](https://pkg.go.dev/github.com/520MianXiangDuiXiang520/GoTools/check_tools)
## daoTools
与数据库相关的工具函数,目前包含:
* `conn`: 一个数据库连接工具
* `Transaction`: 一个数据库事务工具
* `redis`: 一个 redis 连接工具具体用法请参考 [godoc](https://pkg.go.dev/github.com/520MianXiangDuiXiang520/GoTools/gin_tools/dao_tools) 文档
## emailTools
对 goemail 的简单封装,可以更加简单的实现群发,抄送,密送,附件等功能, 具体使用请参考 [godoc](https://pkg.go.dev/github.com/520MianXiangDuiXiang520/GoTools/email_tools)