Files
Kazier/backend/pkg/api/response.go
T
m a6b7f2002b
CI / lint-backend (push) Failing after 1m39s
CI / lint-mobile (push) Canceled after 11m8s
CI / test-backend (push) Canceled after 0s
CI / test-mobile (push) Canceled after 0s
CI / build-backend (push) Canceled after 0s
CI / docker (push) Canceled after 0s
fix backend audit findings (auth, upload, sync, data, ocr, contract)
2026-09-21 19:59:52 +02:00

45 lines
1.1 KiB
Go

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")
}