Add example from PR #121

This commit is contained in:
Javier Provecho Fernandez 2015-03-08 15:50:23 +01:00
parent 0fb7bed1c0
commit 4e0e7d6e16
1 changed files with 41 additions and 0 deletions

View File

@ -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() {