Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any method to doing Aspect-Oriented Programming in Go language [closed]

Tags:

go

aop

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.

like image 847
Zhangxz Avatar asked Feb 14 '19 03:02

Zhangxz


1 Answers

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.

like image 181
Eli Bendersky Avatar answered Nov 15 '22 19:11

Eli Bendersky