I am a Go rookie. I want to use the Prometheus monitoring function level and try to be as generic as possible, like spring transactional. Using aspect oriented programming. I tried the following:
type BizFunc func()
func DoAndMonitor(bizFunc BizFunc) {
// monitor begin
defer func() {
// monitor end
}()
bizFunc()
}
but there is no function type that's compatible with any function.
So I wonder whether this can be implemented in Go?
DoAndMonitor()can call thebizFuncargument because has no parameters. What if it would have? What would you pass to it? Using an anonymous function that takes care of supplying the arguments is one solution, see the answer below. For other possibilities, see Go type for function call