docs(README): 更新文档为中文并完善API参考
- 将README从英文翻译为中文 - 添加详细的API参考文档,包括所有管理接口和枚举值说明 - 补充安装、快速开始、认证方式等使用指南 refactor(client): 优化客户端代码结构并添加详细注释 - 为所有API方法添加中文注释和使用说明 - 改进Client结构体和Option配置的设计 - 统一错误处理和响应结构的文档说明
This commit is contained in:
+19
@@ -5,10 +5,16 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// CreateAccount 创建邮件账号。返回的 AppSecret 是明文,仅此一次,需妥善保存。
|
||||
//
|
||||
// POST /api/v1/accounts ServiceAuth
|
||||
func (c *Client) CreateAccount(ctx context.Context, req CreateAccountReq) (*CreateAccountResp, error) {
|
||||
return post[*CreateAccountResp](c, ctx, "/api/v1/accounts", req)
|
||||
}
|
||||
|
||||
// ListAccounts 分页查询账号。支持按用户、状态、关键字过滤。
|
||||
//
|
||||
// GET /api/v1/accounts?page=&page_size=&user_id=&status=&keyword= ServiceAuth
|
||||
func (c *Client) ListAccounts(ctx context.Context, q AccountListQuery) (*PaginationResult[Account], error) {
|
||||
params := mergeParams(paginationParams(q.PaginationQuery), map[string]interface{}{
|
||||
"user_id": q.UserID,
|
||||
@@ -18,19 +24,32 @@ func (c *Client) ListAccounts(ctx context.Context, q AccountListQuery) (*Paginat
|
||||
return get[*PaginationResult[Account]](c, ctx, "/api/v1/accounts", buildQuery(params))
|
||||
}
|
||||
|
||||
// GetAccount 获取单个账号详情。
|
||||
//
|
||||
// GET /api/v1/accounts/{id} ServiceAuth
|
||||
func (c *Client) GetAccount(ctx context.Context, id uint) (*Account, error) {
|
||||
return get[*Account](c, ctx, fmt.Sprintf("/api/v1/accounts/%d", id), nil)
|
||||
}
|
||||
|
||||
// UpdateAccount 局部更新账号字段(只更新 req 中非 nil 的字段)。
|
||||
//
|
||||
// PUT /api/v1/accounts/{id} ServiceAuth
|
||||
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)
|
||||
}
|
||||
|
||||
// DeleteAccount 删除账号(软删除)。
|
||||
//
|
||||
// DELETE /api/v1/accounts/{id} ServiceAuth
|
||||
func (c *Client) DeleteAccount(ctx context.Context, id uint) error {
|
||||
_, err := del[any](c, ctx, fmt.Sprintf("/api/v1/accounts/%d", id))
|
||||
return err
|
||||
}
|
||||
|
||||
// ResetAccountSecret 重置账号 AppSecret,旧密钥立即失效。
|
||||
// 返回的新 AppSecret 是明文,仅此一次。
|
||||
//
|
||||
// POST /api/v1/accounts/{id}/reset-secret ServiceAuth
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user