Merge branch 'master' of https://github.com/mdigger/gin into mdigger-master
This commit is contained in:
commit
6b6ec5be77
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
Godeps/*
|
||||
!Godeps/Godeps.json
|
10
Godeps/Godeps.json
generated
Normal file
10
Godeps/Godeps.json
generated
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"ImportPath": "github.com/gin-gonic/gin",
|
||||
"GoVersion": "go1.3",
|
||||
"Deps": [
|
||||
{
|
||||
"ImportPath": "github.com/julienschmidt/httprouter",
|
||||
"Rev": "7deadb6844d2c6ff1dfb812eaa439b87cdaedf20"
|
||||
}
|
||||
]
|
||||
}
|
@ -85,13 +85,15 @@ func main() {
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
|
||||
// This handler will match /user/john but will not match neither /user/ or /user
|
||||
r.GET("/user/:name", func(c *gin.Context) {
|
||||
name := c.Params.ByName("name")
|
||||
message := "Hello "+name
|
||||
c.String(200, message)
|
||||
})
|
||||
|
||||
r.GET("/user/:name/:action", func(c *gin.Context) {
|
||||
// However, this one will match /user/john and also /user/john/send
|
||||
r.GET("/user/:name/*action", func(c *gin.Context) {
|
||||
name := c.Params.ByName("name")
|
||||
action := c.Params.ByName("action")
|
||||
message := name + " is " + action
|
||||
|
15
gin.go
15
gin.go
@ -17,12 +17,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
AbortIndex = math.MaxInt8 / 2
|
||||
MIMEJSON = "application/json"
|
||||
MIMEHTML = "text/html"
|
||||
MIMEXML = "application/xml"
|
||||
MIMEXML2 = "text/xml"
|
||||
MIMEPlain = "text/plain"
|
||||
AbortIndex = math.MaxInt8 / 2
|
||||
MIMEJSON = "application/json"
|
||||
MIMEHTML = "text/html"
|
||||
MIMEXML = "application/xml"
|
||||
MIMEXML2 = "text/xml"
|
||||
MIMEPlain = "text/plain"
|
||||
MIMEPOSTForm = "application/x-www-form-urlencoded"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -413,7 +414,7 @@ func (c *Context) Bind(obj interface{}) bool {
|
||||
var b binding.Binding
|
||||
ctype := filterFlags(c.Req.Header.Get("Content-Type"))
|
||||
switch {
|
||||
case c.Req.Method == "GET":
|
||||
case c.Req.Method == "GET" || ctype == MIMEPOSTForm:
|
||||
b = binding.Form
|
||||
case ctype == MIMEJSON:
|
||||
b = binding.JSON
|
||||
|
Loading…
Reference in New Issue
Block a user