Files
gochat/backend/scripts/fix_route_params.py
T
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories:
- backend/: Go module root (cmd, internal, pkg, configs, migrations,
  docs/swagger, scripts, tests, go.mod, Makefile, .air.toml)
- deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd
- docs/: project documentation + reports/ (moved from repo root)
- AGENTS.md: new AI coding-agent guide at repo root

Update all references to the new layout:
- Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root)
- docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile,
  env_file ../../.env, volume mounts ../../backend:/app
- deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile
- CI: working-directory: backend for go commands, file deploy/docker/Dockerfile,
  coverage path backend/coverage.out, health_check backend/scripts/
- backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../
- README: architecture tree, quickstart, config paths updated

Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh,
gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to
preserve history. Build, vet, SQLite tests, and docker compose config verified.
2026-07-07 14:44:12 +08:00

51 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""
Fix Gin radix tree param name conflicts in router.go.
Strategy: unify all param names at the same path position to match Chatwoot conventions.
Known conflicts:
1. conversations/:id vs conversations/:conversation_id → use :conversation_id (matches Chatwoot)
2. accounts/:id (in webhook routes) → already fixed to :account_id
3. notifications/:id → no conflict with sub-resources
4. push_subscriptions/:id → no conflict with sub-resources
For conversations: change all :id under conversations group to :conversation_id
and update corresponding handler code.
"""
import re
router_path = '/home/yanghao05/Workspace/gochat/internal/router/router.go'
with open(router_path) as f:
content = f.read()
# 1. In conversations group, change bare :id to :conversation_id
# These are lines like: conversations.GET("/:id", ...)
# The conversations group starts around line 697 and all its direct :id params need changing
lines = content.split('\n')
changes = []
for i, line in enumerate(lines):
stripped = line.strip()
# Find conversations.GET("/:id", ...) style lines
# Must be under conversations group context
if 'conversations.' in stripped and ':id' in stripped and ':conversation_id' not in stripped:
# Replace :id with :conversation_id in the path
new_line = line.replace('/:id', '/:conversation_id').replace('"/:id"', '"/:conversation_id"')
# But careful: only replace the route path param, not other :id references
# Use regex to specifically target the route path string
new_line = re.sub(r'"/:id"', '"/:conversation_id"', line)
new_line = re.sub(r'"/:id/', '"/:conversation_id/', new_line)
if new_line != line:
changes.append((i+1, line.strip()[:80], new_line.strip()[:80]))
lines[i] = new_line
print(f"Changed {len(changes)} lines in router.go:")
for linenum, old, new in changes:
print(f" Line {linenum}: {old}{new}")
# Also fix line 1372: conversationAttrs Group path uses :conversation_id
# (already correct, no change needed)
with open(router_path, 'w') as f:
f.write('\n'.join(lines))