- 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
36 lines
692 B
Go
36 lines
692 B
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Response struct {
|
|
Data interface{} `json:"data"`
|
|
Error string `json:"error,omitempty"`
|
|
Meta *Meta `json:"meta,omitempty"`
|
|
}
|
|
|
|
type Meta struct {
|
|
Total int `json:"total,omitempty"`
|
|
Page int `json:"page,omitempty"`
|
|
}
|
|
|
|
func JSON(c *gin.Context, status int, data interface{}) {
|
|
c.JSON(status, Response{Data: data})
|
|
}
|
|
|
|
func Error(c *gin.Context, status int, message string) {
|
|
c.JSON(status, Response{Error: message})
|
|
}
|
|
|
|
func Success(c *gin.Context, data interface{}) {
|
|
JSON(c, 200, data)
|
|
}
|
|
|
|
func Created(c *gin.Context, data interface{}) {
|
|
JSON(c, 201, data)
|
|
}
|
|
|
|
func NoContent(c *gin.Context) {
|
|
c.Status(204)
|
|
}
|