上传API接口校验扫描
This commit is contained in:
parent
1a96cde1c8
commit
5036f6b2b0
@ -67,26 +67,37 @@ func (this *MCompGate) suitableMethods() {
|
|||||||
typ := reflect.TypeOf(this.comp)
|
typ := reflect.TypeOf(this.comp)
|
||||||
for m := 0; m < typ.NumMethod(); m++ {
|
for m := 0; m < typ.NumMethod(); m++ {
|
||||||
method := typ.Method(m)
|
method := typ.Method(m)
|
||||||
|
mname := method.Name
|
||||||
|
if mname == "Start" ||
|
||||||
|
mname == "Init" ||
|
||||||
|
mname == "Destroy" ||
|
||||||
|
strings.HasSuffix(mname, "Check") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
this.reflectionRouteHandle(typ, method)
|
this.reflectionRouteHandle(typ, method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//反射注册路由处理函数
|
//反射注册路由处理函数
|
||||||
func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Method) {
|
func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Method) (ret bool) {
|
||||||
mtype := method.Type
|
mtype := method.Type
|
||||||
mname := method.Name
|
mname := method.Name
|
||||||
if method.PkgPath != "" {
|
if method.PkgPath != "" {
|
||||||
|
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if mtype.NumIn() != 3 {
|
if mtype.NumIn() != 3 {
|
||||||
|
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sessionType := mtype.In(1)
|
sessionType := mtype.In(1)
|
||||||
if !sessionType.Implements(typeOfSession) {
|
if !sessionType.Implements(typeOfSession) {
|
||||||
|
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
agrType := mtype.In(2)
|
agrType := mtype.In(2)
|
||||||
if !agrType.Implements(typeOfMessage) {
|
if !agrType.Implements(typeOfMessage) {
|
||||||
|
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if agrType.Kind() != reflect.Ptr {
|
// if agrType.Kind() != reflect.Ptr {
|
||||||
@ -97,14 +108,17 @@ func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Me
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if mtype.NumOut() != 2 {
|
if mtype.NumOut() != 2 {
|
||||||
|
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
returnCodeType := mtype.Out(0)
|
returnCodeType := mtype.Out(0)
|
||||||
if returnCodeType != typeOfErrorCode {
|
if returnCodeType != typeOfErrorCode {
|
||||||
|
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
returnDataType := mtype.Out(1)
|
returnDataType := mtype.Out(1)
|
||||||
if !returnDataType.Implements(typeOfMessage) {
|
if !returnDataType.Implements(typeOfMessage) {
|
||||||
|
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//寻找校验函数
|
//寻找校验函数
|
||||||
@ -119,6 +133,7 @@ func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Me
|
|||||||
log.Panicf("反射注册用户处理函数错误 [%s-%s]校验函数格式异常:%v", this.module.GetType(), mname, err)
|
log.Panicf("反射注册用户处理函数错误 [%s-%s]校验函数格式异常:%v", this.module.GetType(), mname, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
//反射注册路由校验函数
|
//反射注册路由校验函数
|
||||||
|
@ -15,7 +15,7 @@ func (this *apiComp) DelCheck(session comm.IUserSession, req *pb.FriendDelReq) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
//删除好友
|
//删除好友
|
||||||
func (this *apiComp) Del(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelReq) (code pb.ErrorCode, data proto.Message) {
|
func (this *apiComp) Del(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
if code = this.DelCheck(session, req); code != pb.ErrorCode_Success {
|
if code = this.DelCheck(session, req); code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ func (this *Agent) decodeUserData(msg *pb.UserMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//只有login的时候才需要设置Data
|
//只有login的时候才需要设置Data
|
||||||
if msg.MainType == "user" && msg.SubType == "login" {
|
if msg.MainType == string(comm.ModuleUser) && msg.SubType == "login" {
|
||||||
serverId := jsonRet.Get("serverId").Int()
|
serverId := jsonRet.Get("serverId").Int()
|
||||||
account := jsonRet.Get("account").String()
|
account := jsonRet.Get("account").String()
|
||||||
req := &pb.UserLoginReq{
|
req := &pb.UserLoginReq{
|
||||||
@ -160,7 +160,7 @@ func (this *Agent) decodeUserData(msg *pb.UserMessage) error {
|
|||||||
}
|
}
|
||||||
msg.Data = ad
|
msg.Data = ad
|
||||||
} else {
|
} else {
|
||||||
if this.UserId() == "" {
|
if msg.MainType != string(comm.ModuleNotify) && this.UserId() == "" {
|
||||||
return fmt.Errorf("no login")
|
return fmt.Errorf("no login")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,13 @@ API
|
|||||||
type apiComp struct {
|
type apiComp struct {
|
||||||
modules.MCompGate
|
modules.MCompGate
|
||||||
service core.IService
|
service core.IService
|
||||||
module *Notification
|
module *Notify
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.MCompGate.Init(service, module, comp, options)
|
this.MCompGate.Init(service, module, comp, options)
|
||||||
this.module = module.(*Notification)
|
this.module = module.(*Notify)
|
||||||
this.service = service
|
this.service = service
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,17 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
//参数校验
|
//参数校验
|
||||||
func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode) {
|
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
///获取系统公告
|
///获取系统公告
|
||||||
func (this *apiComp) Getlist(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode, data proto.Message) {
|
func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
userexpand *pb.DBUserExpand
|
userexpand *pb.DBUserExpand
|
||||||
|
@ -16,13 +16,13 @@ import (
|
|||||||
///论坛 数据组件
|
///论坛 数据组件
|
||||||
type modelNotifyComp struct {
|
type modelNotifyComp struct {
|
||||||
modules.MCompModel
|
modules.MCompModel
|
||||||
module *Notification
|
module *Notify
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *modelNotifyComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
func (this *modelNotifyComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
||||||
this.MCompModel.Init(service, module, comp, opt)
|
this.MCompModel.Init(service, module, comp, opt)
|
||||||
this.module = module.(*Notification)
|
this.module = module.(*Notify)
|
||||||
this.TableName = "notify"
|
this.TableName = "notify"
|
||||||
//创建uid索引
|
//创建uid索引
|
||||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
|
@ -13,29 +13,29 @@ import (
|
|||||||
开发:李伟
|
开发:李伟
|
||||||
*/
|
*/
|
||||||
func NewModule() core.IModule {
|
func NewModule() core.IModule {
|
||||||
m := new(Notification)
|
m := new(Notify)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type Notification struct {
|
type Notify struct {
|
||||||
modules.ModuleBase
|
modules.ModuleBase
|
||||||
api_comp *apiComp
|
api_comp *apiComp
|
||||||
modelNotify *modelNotifyComp
|
modelNotify *modelNotifyComp
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块名
|
//模块名
|
||||||
func (this *Notification) GetType() core.M_Modules {
|
func (this *Notify) GetType() core.M_Modules {
|
||||||
return comm.ModuleEquipment
|
return comm.ModuleNotify
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块初始化接口 注册用户创建角色事件
|
//模块初始化接口 注册用户创建角色事件
|
||||||
func (this *Notification) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
func (this *Notify) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||||
err = this.ModuleBase.Init(service, module, options)
|
err = this.ModuleBase.Init(service, module, options)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//装备组件
|
//装备组件
|
||||||
func (this *Notification) OnInstallComp() {
|
func (this *Notify) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
||||||
this.modelNotify = this.RegisterComp(new(modelNotifyComp)).(*modelNotifyComp)
|
this.modelNotify = this.RegisterComp(new(modelNotifyComp)).(*modelNotifyComp)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package notify
|
package notify_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"go_dreamfactory/lego/base/rpcx"
|
"go_dreamfactory/lego/base/rpcx"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/modules/notify"
|
||||||
"go_dreamfactory/services"
|
"go_dreamfactory/services"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
"go_dreamfactory/sys/configure"
|
"go_dreamfactory/sys/configure"
|
||||||
@ -49,7 +50,7 @@ func (this *TestService) InitSys() {
|
|||||||
|
|
||||||
var service core.IService
|
var service core.IService
|
||||||
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
||||||
var module = new(Notification)
|
var module = new(notify.Notify)
|
||||||
|
|
||||||
//测试环境下初始化db和cache 系统
|
//测试环境下初始化db和cache 系统
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -4,14 +4,16 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (this *apiComp) LogoutCheck(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) {
|
func (this *apiComp) LogoutCheck(session comm.IUserSession, req *pb.UserLoginReq) (code pb.ErrorCode) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//注销
|
//注销
|
||||||
func (this *apiComp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) (code pb.ErrorCode) {
|
func (this *apiComp) Logout(session comm.IUserSession, rsp *pb.UserLoginReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
|
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"go_dreamfactory/modules/hero"
|
"go_dreamfactory/modules/hero"
|
||||||
"go_dreamfactory/modules/items"
|
"go_dreamfactory/modules/items"
|
||||||
"go_dreamfactory/modules/mail"
|
"go_dreamfactory/modules/mail"
|
||||||
|
"go_dreamfactory/modules/notify"
|
||||||
"go_dreamfactory/modules/shop"
|
"go_dreamfactory/modules/shop"
|
||||||
"go_dreamfactory/modules/story"
|
"go_dreamfactory/modules/story"
|
||||||
"go_dreamfactory/modules/task"
|
"go_dreamfactory/modules/task"
|
||||||
@ -50,6 +51,7 @@ func main() {
|
|||||||
task.NewModule(),
|
task.NewModule(),
|
||||||
story.NewModule(),
|
story.NewModule(),
|
||||||
shop.NewModule(),
|
shop.NewModule(),
|
||||||
|
notify.NewModule(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user