Add missing comments to response.go and middleware.go for better code documentation
This commit is contained in:
parent
94d504ee1e
commit
9c8d982230
2 changed files with 16 additions and 0 deletions
|
|
@ -1,36 +1,44 @@
|
|||
// Package handlers provides HTTP request handlers for the API.
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Response is the standard JSON response format for all API endpoints.
|
||||
type Response struct {
|
||||
Data interface{} `json:"data"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Meta *Meta `json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
// Meta contains pagination information for list endpoints.
|
||||
type Meta struct {
|
||||
Total int `json:"total,omitempty"`
|
||||
Page int `json:"page,omitempty"`
|
||||
}
|
||||
|
||||
// JSON sends a response with the given status code and data.
|
||||
func JSON(c *gin.Context, status int, data interface{}) {
|
||||
c.JSON(status, Response{Data: data})
|
||||
}
|
||||
|
||||
// Error sends an error response with the given status code and message.
|
||||
func Error(c *gin.Context, status int, message string) {
|
||||
c.JSON(status, Response{Error: message})
|
||||
}
|
||||
|
||||
// Success sends a 200 OK response with the given data.
|
||||
func Success(c *gin.Context, data interface{}) {
|
||||
JSON(c, 200, data)
|
||||
}
|
||||
|
||||
// Created sends a 201 Created response with the given data.
|
||||
func Created(c *gin.Context, data interface{}) {
|
||||
JSON(c, 201, data)
|
||||
}
|
||||
|
||||
// NoContent sends a 204 No Content response.
|
||||
func NoContent(c *gin.Context) {
|
||||
c.Status(204)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue