diff --git a/.travis.yml b/.travis.yml index 6532a334..821ce8df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ git: install: - make install +go_import_path: github.com/gin-gonic/gin + script: - make vet - make fmt-check diff --git a/README.md b/README.md index eda1dd70..05b696df 100644 --- a/README.md +++ b/README.md @@ -481,6 +481,52 @@ func startPage(c *gin.Context) { } ``` +### Bind HTML checkboxes + +See the [detail information](https://github.com/gin-gonic/gin/issues/129#issuecomment-124260092) + +main.go + +```go +... + +type myForm struct { + Colors []string `form:"colors[]"` +} + +... + +func formHandler(c *gin.Context) { + var fakeForm myForm + c.Bind(&fakeForm) + c.JSON(200, gin.H{"color": fakeForm.Colors}) +} + +... + +``` + +form.html + +```html +
+``` + +result: + +``` +{"color":["red","green","blue"]} +``` + ### Multipart/Urlencoded binding ```go @@ -559,6 +605,29 @@ func main() { } ``` +#### SecureJSON + +Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to response body if the given struct is array values. + +```go +func main() { + r := gin.Default() + + // You can also use your own secure json prefix + // r.SecureJsonPrefix(")]}',\n") + + r.GET("/someJSON", func(c *gin.Context) { + names := []string{"lena", "austin", "foo"} + + // Will output : while(1);["lena","austin","foo"] + c.SecureJSON(http.StatusOK, names) + }) + + // Listen and serve on 0.0.0.0:8080 + r.Run(":8080") +} +``` + ### Serving static files ```go diff --git a/render/render.go b/render/render.go index 620b0d87..71852364 100644 --- a/render/render.go +++ b/render/render.go @@ -24,7 +24,6 @@ var ( _ HTMLRender = HTMLProduction{} _ Render = YAML{} _ Render = MsgPack{} - _ Render = MsgPack{} ) func writeContentType(w http.ResponseWriter, value []string) {