package api import ( "log" "github.com/gin-gonic/gin" ) const NotImplementedCode = "NOT_IMPLEMENTED" type Meta struct { Page int `json:"page"` PageSize int `json:"pageSize"` Total int `json:"total"` } func OK(c *gin.Context, data any) { c.JSON(200, gin.H{"data": data}) } func OKList(c *gin.Context, data any, page, pageSize, total int) { c.JSON(200, gin.H{ "data": data, "meta": Meta{Page: page, PageSize: pageSize, Total: total}, }) } func Error(c *gin.Context, status int, code, message string) { // LOT 6 §5 : le client ne reçoit que l'enveloppe générique (code + // message sans détail interne — jamais de err.Error() brut). Le détail // va au log serveur pour le diagnostic. path := "" if c.Request != nil && c.Request.URL != nil { path = c.Request.URL.Path } log.Printf("api error: status=%d code=%s message=%s path=%s", status, code, message, path) c.JSON(status, gin.H{ "error": gin.H{"code": code, "message": message}, }) } func NotImplemented(c *gin.Context) { Error(c, 501, NotImplementedCode, "route not implemented yet") }