Skip to content

Go Backend Bot Proxy Endpoints#115

Merged
tgrunnagle merged 2 commits into
mainfrom
iss_100_2026_02-01
Feb 2, 2026
Merged

Go Backend Bot Proxy Endpoints#115
tgrunnagle merged 2 commits into
mainfrom
iss_100_2026_02-01

Conversation

@tgrunnagle
Copy link
Copy Markdown
Owner

Closes #100

Summary

Adds HTTP proxy endpoints to the Go backend that allow frontend clients to spawn and remove bots from game rooms. The backend validates room membership, extracts room credentials, and forwards requests to the FastAPI Bot Service, maintaining a clean API boundary that keeps the Bot Service internal.

Changes Made

backend/

  • Added HandleAddBot handler for POST /api/rooms/{roomId}/bots to spawn bots in a game room
  • Added HandleRemoveBot handler for DELETE /api/rooms/{roomId}/bots/{botId} to remove bots
  • Implemented player token authentication via X-Player-Token or Authorization: Bearer headers
  • Added room validation and credential extraction before forwarding to Bot Service
  • Created request/response types (AddBotRequest, AddBotResponse, RemoveBotResponse) and internal Bot Service types
  • Added path parameter extraction helpers (extractAddBotPathParams, extractRemoveBotPathParams)
  • Configured BOT_SERVICE_URL environment variable (default: http://localhost:8080)
  • Updated routing in main.go to dispatch bot management endpoints

Implementation Details

  • Bot Service requests use a 10-second timeout to prevent hanging connections
  • Room code and password are extracted from the game room and sent to the Bot Service
  • Bot type validation ensures only rule_based or neural_network types are accepted
  • Room activity is updated on successful bot operations for idle timeout tracking

Testing

  • Added table-driven unit tests for extractAddBotPathParams and extractRemoveBotPathParams covering valid paths, invalid paths, UUIDs, and edge cases
  • Added comprehensive tests for HandleAddBot covering:
    • Valid requests with both token header styles
    • Missing/invalid player tokens (401/403)
    • Non-existent rooms (404)
    • Invalid bot types (400)
    • Bot Service errors and unavailability
    • OPTIONS preflight requests
    • Method not allowed cases
  • Added comprehensive tests for HandleRemoveBot covering similar scenarios plus bot-not-found cases
  • Tests use httptest.Server to mock the Bot Service

Additional Notes

@tgrunnagle tgrunnagle merged commit 888d5ba into main Feb 2, 2026
5 checks passed
@tgrunnagle tgrunnagle deleted the iss_100_2026_02-01 branch February 2, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go Backend Bot Proxy

1 participant