From 4e0e7d6e16681b387e1708b61e6e01916ca1494d Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Sun, 8 Mar 2015 15:50:23 +0100 Subject: [PATCH] Add example from PR #121 --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index b6020a2..92d6a0b 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,47 @@ func main() { } ``` +###Multipart Form +```go +package main + +import ( + "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" +) + +type LoginForm struct { + User string `form:"user" binding:"required"` + Password string `form:"password" binding:"required"` +} + +func main() { + + r := gin.Default() + + r.POST("/login", func(c *gin.Context) { + + var form LoginForm + c.BindWith(&form, binding.MultipartForm) + + if form.User == "user" && form.Password == "password" { + c.JSON(200, gin.H{"status": "you are logged in"}) + } else { + c.JSON(401, gin.H{"status": "unauthorized"}) + } + + }) + + r.Run(":8080") + +} +``` + +Test it with: +```bash +$ curl -v --form user=user --form password=password http://localhost:8080/login +``` + #### Grouping routes ```go func main() {