new response middleware functions to simplify middleware
This commit is contained in:
@@ -8,6 +8,26 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func HandleResponses(c *gin.Context) {
|
||||
c.Next()
|
||||
|
||||
if len(c.Errors) > 0 || c.Writer.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
v, ok := c.Get(responseKey{})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
res, ok := v.(Response)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
writeResponse(c, res)
|
||||
}
|
||||
|
||||
func HandleErrors(c *gin.Context) {
|
||||
c.Next()
|
||||
|
||||
@@ -46,7 +66,7 @@ func HandleErrors(c *gin.Context) {
|
||||
c.String(status, msg)
|
||||
}
|
||||
|
||||
func Write(c *gin.Context, res Response) {
|
||||
func writeResponse(c *gin.Context, res Response) {
|
||||
w := c.Writer
|
||||
|
||||
// w.Header() must be set before ResponseWriter.WriteHeader is called
|
||||
|
||||
Reference in New Issue
Block a user