import ( "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.POST("/form", func(c *gin.Context) { name := c.PostForm("name") email := c.PostForm("email") c.JSON(http.StatusOK, gin.H{ "name": name, "email": email, }) }) r.Run() }
import ( "fmt" "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.POST("/login", func(c *gin.Context) { username := c.PostForm("username") password := c.PostForm("password") if username == "admin" && password == "secret" { c.JSON(http.StatusOK, gin.H{"status": "success"}) } else { c.JSON(http.StatusUnauthorized, gin.H{"status": "error"}) } }) r.Run(":8080") }In this example, we define a route "/login" with a POST method. When a request is made to this route, the server retrieves the values of the "username" and "password" form elements using the Context PostForm method. The server then checks if the values are correct and returns a JSON response with the appropriate status.