我是golang的新手,想知道是否有任何方法可以拦截函数。
例如,如果我有:
func (foo Foo) f1(a int) int {...}
func (foo Foo) f2(a, b int) int {...}
func (foo Foo) f3(a, b, c int) int {...}
我想实现一些日志记录功能,而不是在每个函数中放置前置和后置拦截器:
func (foo Foo) f1(a int) int {
preCall()
...
postCall()
}
func (foo Foo) f2(a, b int) int {
preCall()
...
postCall()
}
func (foo Foo) f3(a, b, c int) int {
preCall()
...
postCall()
}
有没有更好的模式来做到这一点?例如Java中的AOP。
蝴蝶不菲
慕尼黑的夜晚无繁华
相关分类