Switch from net/http to gin-gonic web framework
- Added gin-gonic v1.10.0 dependency - Refactored router.go: clean route groups with middleware chains - Refactored all handlers to use gin.Context instead of http.ResponseWriter/*http.Request - Simplified response helpers (JSON, Error, Success, Created, NoContent) - Clean auth middleware using Gin's c.Set() for context - Cleaner route definitions with path parameters (e.g., /domains/:name/users/:id) - Admin routes moved to /api/admin group with RequireAdmin middleware
This commit is contained in:
parent
68285d861a
commit
2834657125
13 changed files with 474 additions and 812 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/imc-vibe/backend/internal/mail"
|
||||
)
|
||||
|
||||
|
|
@ -13,26 +14,21 @@ func NewLogsHandler() *LogsHandler {
|
|||
return &LogsHandler{}
|
||||
}
|
||||
|
||||
func (h *LogsHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
Error(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
return
|
||||
}
|
||||
|
||||
func (h *LogsHandler) List(c *gin.Context) {
|
||||
hours := 1
|
||||
if h := r.URL.Query().Get("hours"); h != "" {
|
||||
if h := c.Query("hours"); h != "" {
|
||||
if n, err := strconv.Atoi(h); err == nil && n > 0 {
|
||||
hours = n
|
||||
}
|
||||
}
|
||||
|
||||
filter := r.URL.Query().Get("filter")
|
||||
filter := c.Query("filter")
|
||||
|
||||
entries, err := mail.GetLogs(hours, filter)
|
||||
if err != nil {
|
||||
Error(w, http.StatusServiceUnavailable, "log service not available")
|
||||
Error(c, http.StatusServiceUnavailable, "log service not available")
|
||||
return
|
||||
}
|
||||
|
||||
Success(w, entries)
|
||||
Success(c, entries)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue