In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to write an annotation-based static code enhancer / generator with golang imitation spring ioc/aop". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to write an annotation-based static code enhancer / generator with golang imitation spring ioc/aop".
SpringSpring implements a lightweight Java Web Service system application framework based on J2EE technology. It has many excellent features, and many companies choose Spring as the basic development architecture of their products or projects. The main features of Spring include: 1. Light weight 2. Control reversal (Inversion of Control, IoC) 3. Facing Container 4. Facing the section (AspectOriented Programming, AOP) 5. Framework flexible 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 and write "Annotation-based static Code Enhancer / Generator" in golang.
Configuration: ComponentScan,Configuration, Bean
Bean statement: Component, Service, Controller
Bean injection: Autowried
AOP comments: Before, After, Around, PointCut
Subgoal (Day 3)
Add ProjectCmd to support project definition
Add auxiliary classes for text scanning: Chars.go, Tokens.go
Define the code generation service interface ICodingService and its supporting interface
Design
Command/ProjectCmd: project definition directive
Common/Chars: character recognition helper class
Common/Tokens: composite text recognition helper class
Service/ICodingService: code generation service interface
Service/iCodingContext: code generation context
Service/iCodingState: service status in status mode
Service/iCmdRunner: define the instruction executor interface to implement the proposed chain of responsibility mode for extension
Service/tInitialState: default service statu
Command/ProjectCmd.go
Project definition directive
Package project_cmdimport ("errors"fmt"learning/gooop/spring/autogen/command"learning/gooop/spring/autogen/common"os"strings") / / ProjectCmd defines a project with name and dirtype ProjectCmd struct {name string dir string} / / ProjectCmdBuilder parses cli input and creates a ProjectCmd instancetype ProjectCmdBuilder intconst gProjectCmdPrefix = "project" var gErrorInvalidProjectCmd = errors.New ("invalid project cmd") Func (me * ProjectCmd) String () string {return fmt.Sprintf ("project s" Me.name, me.dir)} func (me * ProjectCmd) Apply (ctx command.ICmdContext) error {panic ("implements me")} func (me * ProjectCmdBuilder) Build (line string) (error, command.ICmd) {if! common.Tokens.MatchString (line, gProjectCmdPrefix) {return nil, nil} line = strings.TrimSpace (linelen (gProjectCmdPrefix):]) b Name: = common.Tokens.MatchIdentifier (line) if! b {return gErrorInvalidProjectCmd, nil} line = line [len (name):] b, spaces: = common.Tokens.MatchSpaces (line) if! b {return gErrorInvalidProjectCmd, nil} line = line [len (spaces):] b Dir: = common.Tokens.MatchDir (line) if! b {return gErrorInvalidProjectCmd, nil} _, e: = os.Stat (dir) if e! = nil {return e, nil} return nil, & ProjectCmd {name, dir}} common/Chars.go
Character recognition helper class
Package commontype tChars intvar Chars = new (tChars) func (me * tChars) IsSpace (it rune) bool {switch it {case': return true case'\ t': return true case'\ r': return true case'\ n': return true} return false} func ( Me * tChars) Is09 (it rune) bool {return it > ='0' & & it ='1' & & it ='a'& & it ='A' & & it
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.