Add PureJSON renderer (#694)

Closes #693
This commit is contained in:
Filip Figiel
2018-08-20 09:15:31 +02:00
committed by Bo-Yi Wu
parent b7bb9baa64
commit c6110f970c
8 changed files with 133 additions and 4 deletions

View File

@ -991,6 +991,34 @@ func main() {
}
```
#### PureJSON
Normally, JSON replaces special HTML characters with their unicode entities, e.g. `<` becomes `\u003c`. If you want to encode such characters literally, you can use PureJSON instead.
This feature is unavailable in Go 1.6 and lower.
```go
func main() {
r := gin.Default()
// Serves unicode entities
r.GET("/json", func(c *gin.Context) {
c.JSON(200, gin.H{
"html": "<b>Hello, world!</b>",
})
})
// Serves literal characters
r.GET("/purejson", func(c *gin.Context) {
c.PureJSON(200, gin.H{
"html": "<b>Hello, world!</b>",
})
})
// listen and serve on 0.0.0.0:8080
r.Run(":8080)
}
```
### Serving static files
```go