add vendor
This commit is contained in:
@@ -8,28 +8,49 @@ import (
|
||||
// Context custom patch context
|
||||
type Context struct {
|
||||
*gin.Context
|
||||
C map[string]interface{}
|
||||
}
|
||||
|
||||
// CustomMiddle func
|
||||
type CustomMiddle func(*Context)
|
||||
|
||||
// PatchContext func
|
||||
func PatchContext(handler CustomMiddle) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
ctx := &Context{
|
||||
Context: c,
|
||||
}
|
||||
ctx.C = make(map[string]interface{})
|
||||
handler(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// NotFound response
|
||||
func (c *Context) NotFound(msg string) {
|
||||
func (c *Context) NotFound(msg interface{}) {
|
||||
obj := apimsg.GetRes("NotFound", msg)
|
||||
// c.JSON(obj.Status, obj.Obj)
|
||||
c.AbortWithStatusJSON(obj.Status, obj.Obj)
|
||||
}
|
||||
|
||||
// DataFormat error response
|
||||
func (c *Context) DataFormat(msg interface{}) {
|
||||
obj := apimsg.GetRes("DataFormat", msg)
|
||||
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)
|
||||
c.AbortWithStatusJSON(obj.Status, obj.Obj)
|
||||
}
|
||||
|
||||
// ServerError response
|
||||
func (c *Context) ServerError(msg interface{}) {
|
||||
obj := apimsg.GetRes("InternalError", msg)
|
||||
c.AbortWithStatusJSON(obj.Status, obj.Obj)
|
||||
}
|
||||
|
||||
// CustomRes send othen response
|
||||
func (c *Context) CustomRes(name string, msg interface{}) {
|
||||
obj := apimsg.GetRes(name, msg)
|
||||
c.AbortWithStatusJSON(obj.Status, obj.Obj)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package utils
|
||||
|
||||
import "reflect"
|
||||
|
||||
// ToMap struct to map[string]interface{}
|
||||
func ToMap(ss interface{}) map[string]interface{} {
|
||||
t := reflect.ValueOf(ss).Elem()
|
||||
|
||||
smap := make(map[string]interface{})
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
f := t.Field(i)
|
||||
smap[t.Type().Field(i).Name] = f.Interface()
|
||||
}
|
||||
|
||||
return smap
|
||||
}
|
||||
Reference in New Issue
Block a user