mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 14:52:18 +08:00
Removed useless panicking from renderer/context
This commit is contained in:
parent
231ff00d1f
commit
0709ae3b10
@ -16,6 +16,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-contrib/sse"
|
"github.com/gin-contrib/sse"
|
||||||
@ -814,7 +815,11 @@ func (c *Context) Render(code int, r render.Render) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := r.Render(c.Writer); err != nil {
|
if err := r.Render(c.Writer); err != nil {
|
||||||
panic(err)
|
c.Error(err)
|
||||||
|
|
||||||
|
if err == syscall.EPIPE {
|
||||||
|
c.AbortWithStatus(httpStatusClientClosedRequest)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,10 +54,8 @@ var jsonAsciiContentType = []string{"application/json"}
|
|||||||
|
|
||||||
// Render (JSON) writes data with custom ContentType.
|
// Render (JSON) writes data with custom ContentType.
|
||||||
func (r JSON) Render(w http.ResponseWriter) (err error) {
|
func (r JSON) Render(w http.ResponseWriter) (err error) {
|
||||||
if err = WriteJSON(w, r.Data); err != nil {
|
r.WriteContentType(w)
|
||||||
panic(err)
|
return json.NewEncoder(w).Encode(r.Data)
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteContentType (JSON) writes JSON ContentType.
|
// WriteContentType (JSON) writes JSON ContentType.
|
||||||
@ -65,14 +63,6 @@ func (r JSON) WriteContentType(w http.ResponseWriter) {
|
|||||||
writeContentType(w, jsonContentType)
|
writeContentType(w, jsonContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteJSON marshals the given interface object and writes it with custom ContentType.
|
|
||||||
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
|
|
||||||
writeContentType(w, jsonContentType)
|
|
||||||
encoder := json.NewEncoder(w)
|
|
||||||
err := encoder.Encode(&obj)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType.
|
// Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType.
|
||||||
func (r IndentedJSON) Render(w http.ResponseWriter) error {
|
func (r IndentedJSON) Render(w http.ResponseWriter) error {
|
||||||
r.WriteContentType(w)
|
r.WriteContentType(w)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user