This repository has been archived on 2026-01-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cover-letter-templater/backend/utils/responses/responses.go
2025-07-06 21:40:32 +03:00

32 lines
604 B
Go

package responses
import (
"net/http"
"github.com/gin-gonic/gin"
)
func Success(c *gin.Context, data gin.H) {
// Return success to api
c.JSON(200, gin.H{
"success": true,
"data": data,
})
}
func Error(c *gin.Context, err string, code int) {
// Return error to api
c.AbortWithStatusJSON(code, gin.H{
"success": false,
"error": err,
})
}
func NeedsToLogin(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
"success": false,
"error": "Authentication required",
"needsAuthentication": true, // only appears in this error
})
}