GAAS 广汽安道拓GFrame金属件MOM项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

39 lines
1.1 KiB

package rpc
import (
"github.com/kataras/iris"
"github.com/kataras/iris/core/router"
"leit.com/LAPP_GAAS_GFrame/web/middleware/jwts"
"leit.com/LAPP_GAAS_GFrame/web/supports"
)
func RegisterHandler(party router.Party, path string, handler Handler) {
party.Post(path, func(context iris.Context) {
var json interface{}
var jsonArray []interface{}
if context.GetContentLength() > 0 {
if nil != context.ReadJSON(&json) {
supports.Error(context, iris.StatusBadRequest, "JSON解析失败!", nil)
return
}
if json != nil {
if jsonObject, ok := json.([]interface{}); !ok {
supports.Error(context, iris.StatusBadRequest, "JSON解析失败!", nil)
return
} else {
jsonArray = jsonObject
}
}
}
user, ok := jwts.ParseToken(context)
if !ok {
supports.Error(context, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
if result, err := handler.Process(user, jsonArray); err != nil {
supports.Error(context, iris.StatusBadRequest, err.Error(), nil)
} else {
supports.Ok(context, supports.OptionSuccess, result)
}
})
}