有什么方法可以用Go语言进行面向方面的编程 [英] Is there any method to doing Aspect-Oriented Programming in Go language
问题描述
我正在尝试在go程序中使用面向方面的编程,例如,将信息记录在服务中,而不会干扰我的功能代码,但是我发现没有办法.
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通常倾向于魔术"程度低的设计和代码,而是倾向于显式的.中间件是一种常见的设计模式,它提供了许多有关AOP的知识,例如您提到的简单示例-正确设置服务器代码后,您可以注册将自动记录内容的中间件,等等.其中有一些代码示例在转到Web示例网站上查找中间件,而Google搜索将发现更多内容. 本教程讨论了记录中间件等.
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.
这篇关于有什么方法可以用Go语言进行面向方面的编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!