修改工具的调用方式

This commit is contained in:
2025-11-30 13:34:50 +08:00
parent 719238b1f0
commit 23d3840050
5 changed files with 345 additions and 0 deletions

View File

@@ -28,6 +28,9 @@
### 8. 短信工具 (sms)
提供阿里云短信发送功能支持模板短信和批量发送使用Go标准库实现。
### 9. 工厂工具 (factory)
提供从配置直接创建已初始化客户端对象的功能,避免调用方重复实现创建逻辑。
## 安装
### 1. 配置私有仓库(重要)
@@ -61,6 +64,7 @@ go get git.toowon.com/jimmy/go-commom
- [存储工具文档](./docs/storage.md)
- [邮件工具文档](./docs/email.md)
- [短信工具文档](./docs/sms.md)
- [工厂工具文档](./docs/factory.md)
### 快速示例
@@ -175,6 +179,26 @@ smsClient.SendSimple(
)
```
#### 使用工厂直接获取客户端(推荐)
```go
import (
"git.toowon.com/jimmy/go-commom/config"
"git.toowon.com/jimmy/go-commom/factory"
)
// 加载配置并创建工厂
cfg, _ := config.LoadFromFile("./config.json")
fac := factory.NewFactory(cfg)
// 直接获取已初始化的客户端(无需重复实现创建逻辑)
emailClient, _ := fac.GetEmailClient()
smsClient, _ := fac.GetSMSClient()
// 直接使用
emailClient.SendSimple(...)
smsClient.SendSimple(...)
```
更多示例请查看 [examples](./examples/) 目录。
## 版本