new project
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user