func showUserProfile(c *gin.Context) { userID := c.Param("id") userProfile := getUserProfile(userID) if userProfile == nil { c.AbortWithStatus(http.StatusNotFound) return } c.JSON(http.StatusOK, userProfile) }
func showUserProfile(c *gin.Context) { if !isLoggedIn(c) { c.AbortWithStatus(http.StatusUnauthorized) return } userID := c.Param("id") userProfile := getUserProfile(userID) c.JSON(http.StatusOK, userProfile) }Overall, the gin-gonic/gin package is a popular library for building web applications in Go, and the Context AbortWithStatus function is a convenient way to respond to errors or other conditions that require an immediate HTTP response.