func handleGetUser(c *gin.Context) { id := c.Param("id") userID, err := strconv.Atoi(id) if err != nil { // Handle error } // Use userID ... }
func setUserID(c *gin.Context) { userID := getUserIDFromDB() c.Set("userID", userID) } func handleGetUser(c *gin.Context) { userID := c.MustGet("userID").(int) // Use userID ... }Package library: github.com/gin-gonic/gin