func handleRequest(c *gin.Context) { // check if request contains required parameters if c.Param("id") == "" { // abort and return bad request error to the client c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing id parameter"}) return } // continue handling request ... }
func handleRequest(c *gin.Context) { // check if user is authenticated if !isAuthenticated(c) { // abort and return unauthorized error to the client c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "authentication failed"}) return } // continue handling request ... }