refactor(bookmark): 重构 bookmark 服务生成配置和内部引用

将 bookmark 和 user_np 服务的生成配置分离为 server 和 client 包,
并更新了相应的导入路径。同时更新了 OpenAPI 配置文件中的包名、输出路径及
启用 strict-server 模式以增强类型安全。

此外,同步更新了 VFS 服务的客户端和服务端生成配置,并完善了其 OpenAPI
错误响应定义与二进制内容支持,增强了 API 的规范性和健壮性。

修复了部分权限校验逻辑,并调整了中间件注册方式以适配新的严格模式接口。
This commit is contained in:
zzy
2025-09-25 16:15:34 +08:00
parent 24f238f377
commit b2cc27b8f5
18 changed files with 878 additions and 488 deletions

View File

@ -7,10 +7,9 @@ import (
"encoding/json"
"fmt"
api "git.zzyxyz.com/zzy/zzyxyz_go_api/gen/bookmarks"
api "git.zzyxyz.com/zzy/zzyxyz_go_api/gen/bookmarks_client"
"git.zzyxyz.com/zzy/zzyxyz_go_api/internal/vfs"
"git.zzyxyz.com/zzy/zzyxyz_go_api/internal/vfs/models"
"github.com/gin-gonic/gin"
)
type VfsBookMarkService struct {
@ -32,44 +31,44 @@ func NewVfsBookMarkService(serverURL string) (*vfs.ProxyEntry, error) {
}
// Create implements ServiceProxy.
func (v *VfsBookMarkService) Create(c *gin.Context, servicePath string, node *models.VfsNode, data []byte) (string, error) {
func (v *VfsBookMarkService) Create(servicePath string, node *models.VfsNode, data []byte) ([]byte, error) {
ctx := context.Background()
// 解析传入的数据为 BookmarkRequest
var req api.BookmarkRequest
if err := json.Unmarshal(data, &req); err != nil {
return "", err
return nil, err
}
// 调用 bookmark 服务创建书签
resp, err := v.client.CreateBookmarkWithResponse(ctx, int64(node.ID), req)
if err != nil {
return "", err
return nil, err
}
// 处理响应
if resp.JSON201 != nil {
result, err := json.Marshal(resp.JSON201)
data, err := json.Marshal(resp.JSON201)
if err != nil {
return "", err
return nil, fmt.Errorf("marshal response error: %w", err)
}
return string(result), nil
return data, nil
}
// 处理错误情况
if resp.JSON400 != nil {
return "", fmt.Errorf("bad request: %s", resp.JSON400.Message)
return nil, fmt.Errorf("bad request: %s", resp.JSON400.Message)
}
if resp.JSON500 != nil {
return "", fmt.Errorf("server error: %s", resp.JSON500.Message)
return nil, fmt.Errorf("server error: %s", resp.JSON500.Message)
}
return "", fmt.Errorf("unknown error")
return nil, fmt.Errorf("unknown error")
}
// Delete implements ServiceProxy.
func (v *VfsBookMarkService) Delete(c *gin.Context, servicePath string, node *models.VfsNode) error {
func (v *VfsBookMarkService) Delete(servicePath string, node *models.VfsNode) error {
ctx := context.Background()
// 调用 bookmark 服务删除书签
@ -96,7 +95,7 @@ func (v *VfsBookMarkService) Delete(c *gin.Context, servicePath string, node *mo
}
// Get implements ServiceProxy.
func (v *VfsBookMarkService) Get(c *gin.Context, servicePath string, node *models.VfsNode) (any, error) {
func (v *VfsBookMarkService) Get(servicePath string, node *models.VfsNode) ([]byte, error) {
ctx := context.Background()
// 调用 bookmark 服务获取书签
@ -107,7 +106,11 @@ func (v *VfsBookMarkService) Get(c *gin.Context, servicePath string, node *model
// 处理响应
if resp.JSON200 != nil {
return resp.JSON200, nil
data, err := json.Marshal(resp.JSON200)
if err != nil {
return nil, fmt.Errorf("marshal response error: %w", err)
}
return data, nil
}
// 处理错误情况
@ -124,7 +127,7 @@ func (v *VfsBookMarkService) GetName() string {
}
// Update implements ServiceProxy.
func (v *VfsBookMarkService) Update(c *gin.Context, servicePath string, node *models.VfsNode, data []byte) error {
func (v *VfsBookMarkService) Update(servicePath string, node *models.VfsNode, data []byte) error {
ctx := context.Background()
// 解析传入的数据为 BookmarkRequest