5b4774e9c1
- 新增完整的Go客户端库实现,支持邮件服务器API的各种操作 - 实现账户管理、签名管理、邮件发送、审计、配额、通道等功能模块 - 提供ServiceAuth和AppAuth两种认证模式的客户端 - 添加详细的README文档,包含安装指南和使用示例 - 配置.gitignore文件以忽略构建产物和开发工具配置 - 支持分页查询、错误处理和客户端选项配置
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package emailcli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
func (c *Client) CreateAccount(ctx context.Context, req CreateAccountReq) (*CreateAccountResp, error) {
|
|
return post[*CreateAccountResp](c, ctx, "/api/v1/accounts", req)
|
|
}
|
|
|
|
func (c *Client) ListAccounts(ctx context.Context, q AccountListQuery) (*PaginationResult[Account], error) {
|
|
params := mergeParams(paginationParams(q.PaginationQuery), map[string]interface{}{
|
|
"user_id": q.UserID,
|
|
"status": q.Status,
|
|
"keyword": q.Keyword,
|
|
})
|
|
return get[*PaginationResult[Account]](c, ctx, "/api/v1/accounts", buildQuery(params))
|
|
}
|
|
|
|
func (c *Client) GetAccount(ctx context.Context, id uint) (*Account, error) {
|
|
return get[*Account](c, ctx, fmt.Sprintf("/api/v1/accounts/%d", id), nil)
|
|
}
|
|
|
|
func (c *Client) UpdateAccount(ctx context.Context, id uint, req UpdateAccountReq) (*Account, error) {
|
|
return put[*Account](c, ctx, fmt.Sprintf("/api/v1/accounts/%d", id), req)
|
|
}
|
|
|
|
func (c *Client) DeleteAccount(ctx context.Context, id uint) error {
|
|
_, err := del[any](c, ctx, fmt.Sprintf("/api/v1/accounts/%d", id))
|
|
return err
|
|
}
|
|
|
|
func (c *Client) ResetAccountSecret(ctx context.Context, id uint) (*ResetSecretResp, error) {
|
|
return post[*ResetSecretResp](c, ctx, fmt.Sprintf("/api/v1/accounts/%d/reset-secret", id), nil)
|
|
}
|