fix: 恢复 gen route 的 model 参数渲染到 f2a8b98 实现

- 恢复 buildParamToken 函数的直接实现,移除复杂的 builder 模式
- 恢复 buildRenderData 函数的简单实现,提高代码可读性
- 恢复 Render 函数的基础实现,移除过度工程化的验证逻辑
- 修复路由分组路径问题:移除 buildResult 中错误的路径覆盖逻辑
- 当使用 model() 绑定时生成完整的数据库查询函数代码

此提交将 gen route 功能恢复到 commit f2a8b9876e
的实现方式,确保 model 参数渲染符合原始设计。

修复问题:
- 修复路由生成时 "open /v1/medias/routes.gen.go: no such file or directory" 错误
- 确保 model 参数正确生成完整的数据库查询代码而非简化接口
This commit is contained in:
Rogee
2025-09-22 19:01:40 +08:00
parent 4bd9f2f3eb
commit 439456b6ad
4 changed files with 109 additions and 359 deletions

View File

@@ -13,11 +13,10 @@ import (
)
type RouteDefinition struct {
FilePath string
Path string
Name string
Imports []string
Actions []ActionDefinition
Path string
Name string
Imports []string
Actions []ActionDefinition
}
type ActionDefinition struct {
@@ -137,9 +136,9 @@ func (p *routeParser) extractReceiverType(decl *ast.FuncDecl) string {
func (p *routeParser) initializeRoute(recvType string) {
if _, exists := p.routes[recvType]; !exists {
p.routes[recvType] = RouteDefinition{
Name: recvType,
FilePath: p.file,
Actions: []ActionDefinition{},
Name: recvType,
Path: p.file,
Actions: []ActionDefinition{},
}
p.actions[recvType] = []ActionDefinition{}
}
@@ -257,12 +256,6 @@ func (p *routeParser) buildResult() []RouteDefinition {
if actions, exists := p.actions[k]; exists {
route.Actions = actions
route.Imports = p.getUniqueImports(k)
// Set the route path from the first action for backward compatibility
if len(actions) > 0 {
route.Path = actions[0].Route
}
items = append(items, route)
}
}