mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 22:32:26 +08:00
Removed useless panicking from renderer/context
This commit is contained in:
parent
231ff00d1f
commit
0709ae3b10
@ -16,6 +16,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"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 {
|
||||
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.
|
||||
func (r JSON) Render(w http.ResponseWriter) (err error) {
|
||||
if err = WriteJSON(w, r.Data); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return
|
||||
r.WriteContentType(w)
|
||||
return json.NewEncoder(w).Encode(r.Data)
|
||||
}
|
||||
|
||||
// WriteContentType (JSON) writes JSON ContentType.
|
||||
@ -65,14 +63,6 @@ func (r JSON) WriteContentType(w http.ResponseWriter) {
|
||||
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.
|
||||
func (r IndentedJSON) Render(w http.ResponseWriter) error {
|
||||
r.WriteContentType(w)
|
||||
|
Loading…
x
Reference in New Issue
Block a user