refactor bug report structure and add API endpoints for bug report management

This commit is contained in:
Flavio Fois
2026-03-17 15:08:54 +01:00
parent 08ff1da469
commit 8097be88a6
6 changed files with 289 additions and 12 deletions

25
main.go
View File

@@ -47,6 +47,14 @@ func main() {
})
r.Route("/api/v1", func(r chi.Router) {
// Add a header called X-Server
r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Server", "emly-api-go")
next.ServeHTTP(w, r)
})
})
// Health public, no API key required
r.Get("/health", handlers.Health(db))
@@ -60,6 +68,23 @@ func main() {
r.Get("/example", handlers.ExampleGet)
r.Post("/example", handlers.ExamplePost)
})
r.Route("/bug-reports", func(r chi.Router) {
r.Group(func(r chi.Router) {
r.Use(apimw.APIKeyAuth(db))
// Tighter rate-limit on protected group: 30 req / min per IP
r.Use(httprate.LimitByIP(30, time.Minute))
r.Get("/", handlers.GetAllBugReports(db))
r.Get("/{id}", handlers.GetBugReportByID(db))
r.Get("/count", handlers.GetReportsCount(db))
r.Get("/{id}/files", handlers.GetReportFilesByReportID(db))
r.Get("/{id}/files/{file_id}", handlers.GetReportFileByFileID(db))
r.Get("/{id}/zip", handlers.GetBugReportZipById(db))
})
})
})
addr := fmt.Sprintf(":%s", cfg.Port)