Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use golang imitating spring ioc/aop annotation-based static code enhancer / generator

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to use golang imitating spring ioc/aop annotation-based static code enhancer / generator". In daily operation, it is believed that many people have doubts about how to use golang imitating spring ioc/aop annotation-based static code enhancer / generator. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the question of "how to use golang imitating spring ioc/aop annotation-based static code enhancer / generator"! Next, please follow the editor to study!

Hand-play golang spring ioc/aop 2

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. Spring features include lightweight, control inversion (Inversion of Control, IoC), container-oriented, aspect-oriented (AspectOriented Programming, AOP) and framework flexibility. Source code gitee address: https://gitee.com/ioly/learning.gooop original 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 2)

Conceive the mode of operation of app:

Local standlone mode operation

Provide real-time command line interaction based on cli

Generate bypass code: only scan the source code, do not modify the source code, and add a unified suffix to the enhanced code

Design the cli interactive instruction set:

Config save: saving configuration

Config saveas: saving configuration

Watch add: adding code to scan directories

Watch del: remove code scan directory

Watch list: displays the collection of code directories currently scanned

Gen: generate enhancement code, that is, scan all annotations and generate enhancement classes and enhancement methods

Design

Config/IConfiguration: configuring interfac

Command/ICmd: instruction interface

Command/ICmdBuilder: instruction builder interface

Command/ICmdContext: instruction execution context interface

Config_cmd/SaveCmd: saving configuration

Config_cmd/SaveASCmd: saving configuration

Watch_cmd/AddCmd: adding monitoring

Watch_cmd/DelCmd: removing monitoring

Watch_cmd/ListCmd: displays a list of monitored directories

Gen_cmd/GenCmd: generate enhancement classes and enhancement methods

Model/IEventDrivenModel: an event-driven logical orchestration Model

Logger: log API, briefly

Config/IConfiguration.go

Configure Interfac

Package config// IConfiguration defines system configuration interfacetype IConfiguration interface {GetProjectName () string SetProjectName (string) GetWatchPaths () [] string AddWatchPath (string) DelWatchPath (string) Save () error SaveAS (string) error} command/ICmd.go

Instruction interface

Package commandimport "fmt" / / ICmd defines cli command interfacetype ICmd interface {fmt.Stringer / / Apply apply current command into use Apply (ICmdContext) error} command/ICmdBuilder.go

Instruction builder interface

Package command// ICmdBuilder parse input string and create an ICmd instancetype ICmdBuilder interface {Build (string) (error, ICmd)} command/ICmdContext.go

Instruction execution context interface

Package commandimport "learning/gooop/spring/autogen/config" / / ICmdContext provides context info for all commandstype ICmdContext interface {GetConfiguration () config.IConfiguration} config_cmd/SaveCmd.go

Save configuration

Package config_cmdimport ("learning/gooop/spring/autogen/command") / / SaveCmd calls service.Save () to save current configuration In JSON formattype SaveCmd int// SaveCmdBuilder parse cli input and build a SaveCmd instancetype SaveCmdBuilder intconst gSaveCmdString = "config save" var gSaveCmdInstance = new (SaveCmd) func (me * SaveCmd) String () string {return gSaveCmdString} func (me * SaveCmd) Apply (c command.ICmdContext) error {/ / todo: fixme panic ("implements me")} func (me * SaveCmdBuilder) Build (line string) (error, command.ICmd) {if line! = gSaveCmdString {return nil Nil} return nil, gSaveCmdInstance} config_cmd/SaveASCmd.go

Save configuration

Package config_cmdimport ("errors"learning/gooop/spring/autogen/command"strings") / / SaveASCmd calls service.SaveAS () to save current config into specific file In JSON formattype SaveASCmd struct {file string} / / SaveASCmdBuilder parse cli input and returns a SaveASCmd instancetype SaveASCmdBuilder intconst gSaveASCmdPrefix = "config saveas" func (me * SaveASCmd) String () string {return gSaveASCmdPrefix + me.file} func (me * SaveASCmd) Apply (c command.ICmdContext) error {/ / todo: fixme panic ("implements me") func (me * SaveASCmdBuilder) Build (line string) (error, command.ICmd) {if! strings.HasPrefix (line) GSaveASCmdPrefix) {return nil, nil} file: = strings.TrimSpace (line [len (gSaveASCmdPrefix):]) if len (file)

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report