In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "using golang to write an annotation-based static code enhancer / generator method tutorial", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you through the method tutorial of using golang to write annotation-based static code enhancers / generators.
The main features of SpringSpring: 1. Control inversion (Inversion of Control, IoC) 2. Facing Container 3. Aspect-oriented (AspectOriented Programming, AOP) source gitee address: https://gitee.com/ioly/learning.gooop original text link: https://my.oschina.net/ioly target
Refer to the common notes in spring boot and write "Annotation-based static Code Enhancer / Generator" in golang.
Subgoal (Day 10)
The code scan is almost done, and then consider how to enhance it.
Q: sub-goal?
A: take the most commonly used @ RestController annotation as an example to transform the code to achieve ioc injection / aop hook, bean registration, gin integration
Q: specific?
A: a feature enhancement involves a family of related annotations. For example, RestController usually involves RequestMapping, GetMapping, and PostMapping. And almost all Bean will use Autowired.
Q: how to implement, organize and expand?
A: all extensions must correspond to chain / table structures. The system will define the enhancer interface and the implementation of multiple enhancers. Each enhancer identifies a core annotation (such as RestController) and its associated annotations (such as GetMapping) and adds related code to the code model.
Q: who runs and invokes these enhancers?
A: I originally wanted to make standlone app, but now it seems that it may be more convenient to write a xx_test.go and run it by integrating the enhancer package directly into the project.
Q: what is the difficulty?
A: without a doubt, Autowired is the key. In what scope, how to match Implementation, circular dependencies, and appropriate initialization.
Q: how to compromise?
A: the answer almost always simplifies the problem model.
Q: how do I start?
A: the first step is to add the Clone () method to all the code models to provide material for the enhancer.
Domain/IClonable.go
Clone (deep copy) interface
Package domaintype IClonable interface {Clone () interface {}} domain/StructInfo.go
All code models implement the IClonable interface. Here, take StructInfo as an example.
Func (me * StructInfo) Clone () interface {} {it: = new (StructInfo) it.CodeFile = me.CodeFile it.LineNO = me.LineNO it.Name = me.Name it.Fields = make ([] * FieldInfo, len (me.Fields)) for I V: = range me.Fields {it.Fields [I] = v.Clone (). (* FieldInfo) it.Fields [I] .Struct = it} it.Methods = make ([] * MethodInfo, len (me.Methods)) for I V: = range me.Methods {it.Methods [I] = v.Clone (). (* MethodInfo) it.Methods [I] .Struct = it} it.Annotations = make ([] * AnnotationInfo, len (me.Annotations)) for I V: = range me.Annotations {it.Annotations [I] = v.Clone (). (* AnnotationInfo)} return it} so far I believe you have a better understanding of the "method tutorial for writing annotation-based static code enhancers / generators using golang", so you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.