SimpleCloudNotifier/server/common/ginresp/wrapper.go

22 lines
304 B
Go
Raw Normal View History

2022-11-13 19:17:07 +01:00
package ginresp
import "github.com/gin-gonic/gin"
type WHandlerFunc func(*gin.Context) HTTPResponse
func Wrap(fn WHandlerFunc) gin.HandlerFunc {
2022-11-18 21:25:40 +01:00
return func(g *gin.Context) {
2022-11-13 19:17:07 +01:00
2022-11-18 21:25:40 +01:00
wrap := fn(g)
2022-11-13 19:17:07 +01:00
2022-11-18 21:25:40 +01:00
if g.Writer.Written() {
2022-11-13 19:17:07 +01:00
panic("Writing in WrapperFunc is not supported")
}
2022-11-18 21:25:40 +01:00
wrap.Write(g)
2022-11-13 19:17:07 +01:00
}
}