I'm trying to use Aspect-Oriented Programming in go program, For example, log the info in service, Without intrusion to my function codes, But I find there is not a method to do.
Go generally leans towards design and code low on "magic", preferring explicitness. Middleware is a common design pattern that provides a lot of what folks do with AOP, like the simple example you mention - when your server code is set up properly, you can register middleware that will automatically log things, etc. There are some code samples for middleware on the Go Web Examples site, and googling will uncover much more. This tutorial talks about logging middleware, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With