This commit is contained in:
Jay
2018-04-17 17:16:03 +08:00
parent 880a32a9c8
commit a45b1f3603
6 changed files with 181 additions and 10 deletions
+35
View File
@@ -0,0 +1,35 @@
package context
import (
"git.trj.tw/golang/go-gallery/modules/apimsg"
"github.com/gin-gonic/gin"
)
// Context custom patch context
type Context struct {
*gin.Context
}
type CustomMiddle func(*Context)
func PatchContext(handler CustomMiddle) gin.HandlerFunc {
return func(c *gin.Context) {
ctx := &Context{
Context: c,
}
handler(ctx)
}
}
// NotFound response
func (c *Context) NotFound(msg string) {
obj := apimsg.GetRes("NotFound", msg)
// c.JSON(obj.Status, obj.Obj)
c.AbortWithStatusJSON(obj.Status, obj.Obj)
}
// Success response
func (c *Context) Success(msg interface{}) {
obj := apimsg.GetRes("Success", msg)
c.JSON(obj.Status, obj.Obj)
}