From ce26751a5a3ed13e9a6aa010d9a7fa767de91b8c Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Thu, 28 Jan 2016 02:32:44 +0900 Subject: [PATCH 1/4] add import path to .travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 695f0b7e..e4f7e05e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ go: - 1.4.2 - tip +go_import_path: github.com/gin-gonic/gin + script: - go get golang.org/x/tools/cmd/cover - go get github.com/mattn/goveralls From bf9758ca05e47a74d55995ef62042a1c62cbb53c Mon Sep 17 00:00:00 2001 From: Eason Lin Date: Sun, 9 Jul 2017 01:54:43 +0800 Subject: [PATCH 2/4] Add SecureJSON doc --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index eda1dd70..cc97c7a5 100644 --- a/README.md +++ b/README.md @@ -559,6 +559,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 From df3b79e805233f553c0495cfa1fb76766b9d80b3 Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Sun, 9 Jul 2017 11:02:44 +0200 Subject: [PATCH 3/4] docs(readme): add binding html checkbox example, close #129 (#994) --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index cc97c7a5..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 +
+

Check some colors

+ + + + + + + +
+``` + +result: + +``` +{"color":["red","green","blue"]} +``` + ### Multipart/Urlencoded binding ```go From 8436a9d829f22f56cbc059e06a68d19163161391 Mon Sep 17 00:00:00 2001 From: Eason Lin Date: Mon, 10 Jul 2017 14:45:19 +0800 Subject: [PATCH 4/4] fix(render): remove repeated static check. (#998) --- render/render.go | 1 - 1 file changed, 1 deletion(-) 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) {