Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否支持在定义路由方法前后自定义前置方法或后置方法 #906

Open
xiejunshi opened this issue Oct 26, 2020 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@xiejunshi
Copy link

在Sayhello方法前后自定义前置方法和后置方法

https://go-chassis.readthedocs.io/en/latest/getstarted/writing-rest.html

@xiejunshi xiejunshi added the bug Something isn't working label Oct 26, 2020
@tianxiaoliang
Copy link
Member

这个需求倒是合理,不过请问用户故事是什么,以及为何handler chain设计无法满足需求。

@tianxiaoliang tianxiaoliang added enhancement New feature or request and removed bug Something isn't working labels Oct 27, 2020
@Reese1995
Copy link
Contributor

监控、调用次数统计、日志等系统功能代码与业务代码解耦,类似JAVA AOP

@tianxiaoliang
Copy link
Member

https://go-chassis.readthedocs.io/en/latest/middleware.html 那这个设计我理解完全满足你的这些场景

@tianxiaoliang
Copy link
Member

2位是否还有疑问,是否有其他的用户故事 handler chain无法满足

@Reese1995
Copy link
Contributor

看了这个设计,其实并不能满足我们的需求。这个是框架级别的AOP。
我们的需求是希望能在业务方法上做自定义的AOP。类似AspectJ. 做业务逻辑的增强

@Reese1995
Copy link
Contributor

Anyway,感谢你的耐心解答!

@tianxiaoliang
Copy link
Member

@Reese1995 你可以设计一个这样的方案,合入到go chassis,这种重大特性足以让你成为go chassis的维护者。

相对于spring 的 aop,由于go没有注解,所以得通过配置文件的方式声明一些方法的切面处理方式

@rentiansheng
Copy link

rentiansheng commented Oct 10, 2022

其实将go-restful router 的Filter 放出来即可。这样业务可以完成
eg :

func(r *restful.Request, w *restful.Response, filterChain *restful.FilterChain) {
     // prefix hook
    chain.ProcessFilter(request, response)
    // suffix hook or can be defer 
}

@tianxiaoliang
Copy link
Member

在后续的多样的restful框架集成中,我们都遵循原生的写法了gin-go,还有go-fiber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants