Skip to content
Myr

fix README.md code bug and Change map to gin.H (#1963)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

``` go func main() { r := gin.Default() // r.GET("/JSONP?callback=x", func(c *gin.Context) { // old r.GET("/JSONP", func(c *gin.Context) { // new data := gin.H{ "foo": "bar", } //callback is x // Will output : x({\"foo\":\"bar\"}) c.JSONP(http.StatusOK, data) }) // Listen and serve on 0.0.0.0:8080 r.Run(":8080") } // client // curl http://127.0.0.1:8080/JSONP?callback=x // old output // 404 page not found // new output // x({"foo":"bar"}) ``` Most of the sample code in the documentation map[string]interface{} is represented by gin.H. gin.H is a very important place for me to like gin, can write a lot less code

authored by guonaihong · committed by thinkerou · parent f98b339 · Browse files · 1 file+7 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−4 removed

  • other:+7 added−4 removed

1 file+7 added−4 removed

modified:README.md+7 added-4 removed
1117 unmodified lines
1118```go1119func main() {1120 r := gin.Default()11211122 r.GET("/JSONP?callback=x", func(c *gin.Context) {1123 data := map[string]interface{}{1122 r.GET("/JSONP", func(c *gin.Context) {1123 data := gin.H{1124 "foo": "bar",1125 }1126 1127 //callback is x
2 unmodified lines
1130 })11311132 // Listen and serve on 0.0.0.0:80801133 r.Run(":8080")11341135 // client1136 // curl http://127.0.0.1:8080/JSONP?callback=x1137}1138```11391140#### AsciiJSON
4 unmodified lines
1145func main() {1146 r := gin.Default()11471148 r.GET("/someJSON", func(c *gin.Context) {1146 data := map[string]interface{}{1149 data := gin.H{1150 "lang": "GO语言",1151 "tag": "<br>",1152 }1153
200 unmodified lines
1354 })1355 router.LoadHTMLFiles("./testdata/template/raw.tmpl")13561357 router.GET("/raw", func(c *gin.Context) {1355 c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{1358 c.HTML(http.StatusOK, "raw.tmpl", gin.H{1359 "now": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC),1360 })1361 })1362
754 unmodified lines