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:
Christoph Haas 2026-03-22 23:28:28 +01:00
parent 68285d861a
commit 2834657125
13 changed files with 474 additions and 812 deletions

View file

@ -1,8 +1,7 @@
package handlers
import (
"encoding/json"
"net/http"
"github.com/gin-gonic/gin"
)
type Response struct {
@ -16,26 +15,22 @@ type Meta struct {
Page int `json:"page,omitempty"`
}
func JSON(w http.ResponseWriter, status int, data interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(Response{Data: data})
func JSON(c *gin.Context, status int, data interface{}) {
c.JSON(status, Response{Data: data})
}
func Error(w http.ResponseWriter, status int, message string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(Response{Error: message})
func Error(c *gin.Context, status int, message string) {
c.JSON(status, Response{Error: message})
}
func Success(w http.ResponseWriter, data interface{}) {
JSON(w, http.StatusOK, data)
func Success(c *gin.Context, data interface{}) {
JSON(c, 200, data)
}
func Created(w http.ResponseWriter, data interface{}) {
JSON(w, http.StatusCreated, data)
func Created(c *gin.Context, data interface{}) {
JSON(c, 201, data)
}
func NoContent(w http.ResponseWriter) {
w.WriteHeader(http.StatusNoContent)
func NoContent(c *gin.Context) {
c.Status(204)
}