Przeglądaj źródła

Merge branch 'master' of https://github.com/mdigger/gin into mdigger-master

Manu Mtz-Almeida 11 lat temu
rodzic
commit
6b6ec5be77
5 zmienionych plików z 26 dodań i 11 usunięć
  1. 2 0
      .gitignore
  2. 10 0
      Godeps/Godeps.json
  3. 5 3
      README.md
  4. 8 7
      gin.go
  5. 1 1
      logger.go

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+Godeps/*
+!Godeps/Godeps.json

+ 10 - 0
Godeps/Godeps.json

@@ -0,0 +1,10 @@
+{
+	"ImportPath": "github.com/gin-gonic/gin",
+	"GoVersion": "go1.3",
+	"Deps": [
+		{
+			"ImportPath": "github.com/julienschmidt/httprouter",
+			"Rev": "7deadb6844d2c6ff1dfb812eaa439b87cdaedf20"
+		}
+	]
+}

+ 5 - 3
README.md

@@ -84,20 +84,22 @@ func main() {
 ```go
 ```go
 func main() {
 func main() {
 	r := gin.Default()
 	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) {
 	r.GET("/user/:name", func(c *gin.Context) {
 		name := c.Params.ByName("name")
 		name := c.Params.ByName("name")
 		message := "Hello "+name
 		message := "Hello "+name
 		c.String(200, message)
 		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")
 		name := c.Params.ByName("name")
 		action := c.Params.ByName("action")
 		action := c.Params.ByName("action")
 		message := name + " is " + action
 		message := name + " is " + action
 		c.String(200, message)
 		c.String(200, message)
 	})
 	})
-
+	
 	// Listen and server on 0.0.0.0:8080
 	// Listen and server on 0.0.0.0:8080
 	r.Run(":8080")
 	r.Run(":8080")
 }
 }

+ 8 - 7
gin.go

@@ -17,12 +17,13 @@ import (
 )
 )
 
 
 const (
 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 (
 const (
@@ -413,7 +414,7 @@ func (c *Context) Bind(obj interface{}) bool {
 	var b binding.Binding
 	var b binding.Binding
 	ctype := filterFlags(c.Req.Header.Get("Content-Type"))
 	ctype := filterFlags(c.Req.Header.Get("Content-Type"))
 	switch {
 	switch {
-	case c.Req.Method == "GET":
+	case c.Req.Method == "GET" || ctype == MIMEPOSTForm:
 		b = binding.Form
 		b = binding.Form
 	case ctype == MIMEJSON:
 	case ctype == MIMEJSON:
 		b = binding.JSON
 		b = binding.JSON

+ 1 - 1
logger.go

@@ -69,7 +69,7 @@ func Logger() HandlerFunc {
 		latency := end.Sub(start)
 		latency := end.Sub(start)
 		stdlogger.Printf("[GIN] %v |%s %3d %s| %12v | %s %4s %s\n",
 		stdlogger.Printf("[GIN] %v |%s %3d %s| %12v | %s %4s %s\n",
 			end.Format("2006/01/02 - 15:04:05"),
 			end.Format("2006/01/02 - 15:04:05"),
-			color, c.Writer.Status(), reset,
+			color, code, reset,
 			latency,
 			latency,
 			requester,
 			requester,
 			c.Req.Method, c.Req.URL.Path,
 			c.Req.Method, c.Req.URL.Path,