29 lines
582 B
Go
29 lines
582 B
Go
package auxhttp
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type GenericResponse[T any] struct {
|
|
Result T `json:"result,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
Error bool `json:"error"`
|
|
}
|
|
|
|
func SendError(c *gin.Context, err error) {
|
|
var response GenericResponse[interface{}]
|
|
response.Error = true
|
|
if err != nil {
|
|
response.Message = err.Error()
|
|
}
|
|
c.AbortWithStatusJSON(http.StatusOK, response)
|
|
}
|
|
|
|
func SendResult(c *gin.Context, result any) {
|
|
var response GenericResponse[any]
|
|
response.Result = result
|
|
c.JSON(http.StatusOK, response)
|
|
}
|