new response middleware functions to simplify middleware

This commit is contained in:
2026-01-23 22:16:11 -07:00
parent 3fd533091c
commit 649595718c
7 changed files with 159 additions and 149 deletions
+21 -1
View File
@@ -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