mirror of
https://github.com/xxjwxc/ginrpc.git
synced 2025-09-26 19:21:18 +08:00
add beforeAfter muilt
This commit is contained in:
18
common.go
18
common.go
@@ -98,8 +98,13 @@ func (b *_Base) beforCall(c *gin.Context, tvl, obj reflect.Value, req interface{
|
||||
if bfobj, ok := obj.Interface().(GinBeforeAfter); ok { // 本类型
|
||||
is = bfobj.GinBefore(info)
|
||||
}
|
||||
if is && b.beforeAfter != nil {
|
||||
is = b.beforeAfter.GinBefore(info)
|
||||
if is && len(b.beforeAfter) > 0 {
|
||||
for _, call := range b.beforeAfter {
|
||||
is = call.GinBefore(info)
|
||||
if !is {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return info, is
|
||||
}
|
||||
@@ -109,8 +114,13 @@ func (b *_Base) afterCall(info *GinBeforeAfterInfo, obj reflect.Value) bool {
|
||||
if bfobj, ok := obj.Interface().(GinBeforeAfter); ok { // 本类型
|
||||
is = bfobj.GinAfter(info)
|
||||
}
|
||||
if is && b.beforeAfter != nil {
|
||||
is = b.beforeAfter.GinAfter(info)
|
||||
if is && len(b.beforeAfter) > 0 {
|
||||
for _, call := range b.beforeAfter {
|
||||
is = call.GinAfter(info)
|
||||
if !is {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return is
|
||||
}
|
||||
|
Binary file not shown.
5
gen.go
5
gen.go
@@ -58,8 +58,9 @@ func AddGenOne(handFunName, routerPath string, methods []string, thirdParty []Ge
|
||||
}
|
||||
|
||||
func GetThirdParty(routerPath, thirdParty string) (*GenThirdParty, error) {
|
||||
if _, ok := _genMap[fmt.Sprintf("%v-%v", routerPath, thirdParty)]; ok {
|
||||
tmp := _genMap[routerPath]
|
||||
key := fmt.Sprintf("%v-%v", routerPath, thirdParty)
|
||||
if _, ok := _genMap[key]; ok {
|
||||
tmp := _genMap[key]
|
||||
return &GenThirdParty{
|
||||
Name: tmp.Name,
|
||||
Note: tmp.Note,
|
||||
|
@@ -20,7 +20,7 @@ type _Base struct {
|
||||
apiFun NewAPIFunc
|
||||
apiType reflect.Type
|
||||
outPath string // output path.输出目录
|
||||
beforeAfter GinBeforeAfter
|
||||
beforeAfter []GinBeforeAfter
|
||||
isOutDoc bool
|
||||
recoverErrorFunc RecoverErrorFunc
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func WithOutDoc(b bool) Option {
|
||||
// WithBeforeAfter set before and after call.设置对象调用前后执行中间件
|
||||
func WithBeforeAfter(beforeAfter GinBeforeAfter) Option {
|
||||
return optionFunc(func(o *_Base) {
|
||||
o.beforeAfter = beforeAfter
|
||||
o.beforeAfter = append(o.beforeAfter, beforeAfter)
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user