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
T

32 lines
602 B
Go
Raw Normal View History

2025-07-06 16:46:21 +03:00
package responses
2025-07-05 22:17:14 +03:00
import (
2025-07-06 18:13:26 +03:00
"net/http"
2025-07-05 22:17:14 +03:00
"github.com/gin-gonic/gin"
)
2025-07-09 23:19:31 +03:00
func Success(c *gin.Context, data any) {
2025-07-05 22:17:14 +03:00
// 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
2025-07-06 21:40:32 +03:00
c.AbortWithStatusJSON(code, gin.H{
2025-07-05 22:17:14 +03:00
"success": false,
"error": err,
})
}
2025-07-06 18:13:26 +03:00
func NeedsToLogin(c *gin.Context) {
2025-07-06 21:40:32 +03:00
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
2025-07-06 18:13:26 +03:00
"success": false,
"error": "Authentication required",
"needsAuthentication": true, // only appears in this error
})
}