- 8b generoi Pythonia (osaa sen), 30b konvertoi Go:ksi - convert-go.md prompti: FastAPI→Chi, SQLAlchemy→database/sql mappaukset - Koodigenerointi käyttää Python golden+promptia kun convert-model asetettu - Vaihe [3.5/5] konvertointia varten
1.0 KiB
1.0 KiB
Convert the following Python FastAPI project to Go using Chi router and modernc.org/sqlite.
OUTPUT: Return ALL files with === markers: === go.mod === === models.go === === handlers.go === === main.go === === handlers_test.go ===
CONVERSION RULES:
- package main for all files
- Pydantic models → Go structs with json tags
- SQLAlchemy ORM → database/sql with raw SQL and RETURNING clause
- FastAPI routes → Chi router: r.Post("/path", handler(db))
- Handlers are closures: func handler(db *sql.DB) http.HandlerFunc
- Depends(get_db) → State passed via closure over *sql.DB
- HTTPException(404) → http.Error(w, "not found", http.StatusNotFound)
- POST returns http.StatusCreated (201), DELETE returns http.StatusNoContent (204)
- sql.ErrNoRows for not-found checks
- TestClient → httptest.NewServer + setupTestServer helper
- test.db → sql.Open("sqlite", ":memory:")
- Empty list: return []Entity{} not nil
- import _ "modernc.org/sqlite" (pure Go driver, no CGO)
- import "github.com/go-chi/chi/v5"
- No markdown fences in output — just raw code