Création de 9 fichiers neufs pour décharger AGENTS.md (1296 lignes →
~130) en documents lazy-loadables, compatibles avec la limite de
contexte 128k de Mistral Vibe (cf. ARCODANGE migration Phase 1,
Tâche 6 du curriculum).
Sept guides ciblés sous documentation/ :
- HISTORY.md : phases historiques 1-9 du développement
- CLI.md : commandes CLI, server lifecycle, config DLC_*
- API.md : endpoints REST, OpenAPI, Greet v1/v2
- OBSERVABILITY.md : OpenTelemetry + Jaeger, sampler types, test
- TROUBLESHOOTING.md : issues connues + pointeurs vers guides spé
- CODE_EXAMPLES.md : snippets endpoint/logging/context, pointeurs ADR
- ROADMAP.md : potential features, architectural improvements
Deux fichiers racine :
- CHANGELOG.md : user-facing, format Keep a Changelog
- AGENT_CHANGELOG.md : décisions structurantes des agents AI
(référencé par AGENTS.md, n'existait pas)
Le contenu est extrait fidèlement d'AGENTS.md sans réinterprétation.
Phase C (réécriture AGENTS.md court) suit dans le commit suivant.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
1.7 KiB
Markdown
60 lines
1.7 KiB
Markdown
# Code Examples
|
|
|
|
Snippets and patterns used across the `dance-lessons-coach` codebase. Extracted from the original `AGENTS.md` (Tâche 6 restructure).
|
|
|
|
## Adding a New API Endpoint
|
|
|
|
```go
|
|
// 1. Add to interface
|
|
func (h *apiV1GreetHandler) RegisterRoutes(router chi.Router) {
|
|
router.Get("/", h.handleGreetQuery)
|
|
router.Get("/{name}", h.handleGreetPath)
|
|
router.Post("/custom", h.handleCustomGreet) // New endpoint
|
|
}
|
|
|
|
// 2. Implement handler
|
|
func (h *apiV1GreetHandler) handleCustomGreet(w http.ResponseWriter, r *http.Request) {
|
|
// Parse request
|
|
// Call service
|
|
// Return JSON response
|
|
}
|
|
```
|
|
|
|
## Logging with Zerolog
|
|
|
|
```go
|
|
// Trace level logging
|
|
log.Trace().Ctx(ctx).Str("key", "value").Msg("message")
|
|
|
|
// Info level
|
|
log.Info().Msg("Important event")
|
|
|
|
// Error level
|
|
log.Error().Err(err).Msg("Error occurred")
|
|
```
|
|
|
|
For the full logging strategy (when to use Trace vs Info, performance considerations), see [ADR-0003 — Zerolog Logging](../adr/0003-zerolog-logging.md).
|
|
|
|
## Using `context.Context`
|
|
|
|
```go
|
|
// Pass context through calls
|
|
func handler(w http.ResponseWriter, r *http.Request) {
|
|
result := service.Greet(r.Context(), "John")
|
|
// ...
|
|
}
|
|
|
|
// Create context with values
|
|
ctx := context.WithValue(r.Context(), "key", "value")
|
|
|
|
// Create context with timeout
|
|
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
|
|
defer cancel()
|
|
```
|
|
|
|
For the rationale behind context-aware services, see [ADR-0004 — Interface-Based Design](../adr/0004-interface-based-design.md).
|
|
|
|
## Best Practices Reminders
|
|
|
|
For higher-level guidance on code organization, error handling, performance, and testing, see [`AGENT_USAGE_GUIDE.md`](AGENT_USAGE_GUIDE.md#best-practices) section "Best Practices".
|