34 lines
691 B
Go
34 lines
691 B
Go
|
package context
|
||
|
|
||
|
import "github.com/gin-gonic/gin"
|
||
|
import "github.com/gin-gonic/gin/binding"
|
||
|
|
||
|
// Context - custom http context
|
||
|
type Context struct {
|
||
|
*gin.Context
|
||
|
}
|
||
|
|
||
|
// CustomMiddle -
|
||
|
type CustomMiddle func(*Context)
|
||
|
|
||
|
// PatchCtx - change custom middle to gin middle
|
||
|
func PatchCtx(handler CustomMiddle) gin.HandlerFunc {
|
||
|
return func(c *gin.Context) {
|
||
|
ctx := &Context{
|
||
|
Context: c,
|
||
|
}
|
||
|
handler(ctx)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BindData - binding data
|
||
|
func (c *Context) BindData(i interface{}) error {
|
||
|
b := binding.Default(c.Request.Method, c.ContentType())
|
||
|
return c.ShouldBindWith(i, b)
|
||
|
}
|
||
|
|
||
|
// CustomRes -
|
||
|
func (c *Context) CustomRes(status int, msg interface{}) {
|
||
|
c.AbortWithStatusJSON(status, msg)
|
||
|
}
|