当前位置:网站首页>My first experience of go+ language -- a collection of notes on learning go+ design architecture
My first experience of go+ language -- a collection of notes on learning go+ design architecture
2022-06-25 12:47:00 【Coconut brine Engineer】
Go+ Installation tutorial for
There is a share in front , Through train :https://bbs.csdn.net/topics/603567061
Go+ Overall architecture

The starting point :Go+ Source code
End : An executable file ( Software ) or A bag (package)
The process : Enter the source code , In the middle token flow , experience AST Abstract syntax tree ,Dom Writer It's like a container , You can fill it with things , Finally can form Go The abstract syntax tree of , adopt go The command-line tool converts to an executable file .
The build process :
1)gop/token
- token The concept of compilation principle is similar to the words in natural language
- The source code is a stream of bytes :[]byte
- Need to pass through lex Process becomes token flow :[]token
2)gop/scanner
- scanner In compiling principle lex The process ( Lexical analysis )
- It usually does not require us to actively invoke , It's about using parser call
3)gop/parser
- In compiling principle parser The process ( Syntax analysis ), Responsible for token The circulation is DOM( namely []token => AST)
parser How to use :Go+ And Go It's the same prototype
func(os.FileInfo)bool,mode Mode)(pkgs map[string]*ast.Package,first error) ```
- fset: It is mainly used to record file offset offset And row number line:col The relationship between
- path: The path where the source code is located
- filter: Filter the file path
- mode: Some control parser Process of flags, It can be transmitted 0
- pkgs: Got AST
- first: stay parser When something goes wrong , The first error that occurred
4)gop/ast
- AST The full name of is abstract syntax tree , It's language DOM
- DOM It is a classic pattern in text processing (XML/json And other general documents have their own DOM, This and language have their own AST Essentially the same )
5)gop/cl
- compile ( Syntax analysis ): Responsible for the Go+AST Convert to right gox DOM Writer Call to
- It means cl The implementation is from Go+AST DOM To another DOM Transformation of
cl How to use
*Config)(p *gox.Package,err error) ```
- pkgPath: The target to compile Go+pkg Of import route
- pkg: The target to compile Go+pkg Of AST
- conf: Configuration for compilation
- p: Generated gox DOM Writer, Other interfaces have been called to complete the format conversion
- err: If an error occurs during compilation , All compilation errors are returned
6)gox
- It's a Go Linguistic DOM Writer Components , Used to generate Go AST
- therefore cl+gox It's done Go+AST To Go AST Transformation
gox How to use
Part to cl Irrigation data , To realize format conversion , One part is used to generate Go AST/Source Of
7)go
- With Go AST/Source after , You can use it go tools To compile
gop run . The core processes (hello world Implementation process )
fset:= token.NewFileSet()
pkgGops,err:= parser.ParseDir(fset,".",nil,0)
pfgFox,err:= cl.NewPackage("main",pkgGopx["mian"].nil)
err = gox.WriteFile("gop_autogen.go",pkgGox,false)
err = exec.Command("go","run","gop_autogen.go").Run()
边栏推荐
- Talk about 11 key techniques of high availability
- Draw the satellite sky map according to the azimuth and elevation of the satellite (QT Implementation)
- Concat(), join(), reverse(), sort() method in JS array
- Node child processes and threads
- mysql FIND_ IN_ Set function
- 使用Visio画立方体
- The amount is verified, and two zeros are spliced by integers during echo
- High performance + million level Excel data import and export
- 百度搜索稳定性问题分析的故事
- Singleton mode in PHP to reduce memory consumption
猜你喜欢

Zhangxiaobai's road of penetration (IV) -- detailed explanation of XSS cross site script vulnerabilities

Go novice exploration road 2

3+1 guarantee: how is the stability of the highly available system refined?

(6) Pyqt5--- > window jump (registration login function)

2021-09-02

Service charge and time setting code sharing involved in crmeb withdrawal process

更新pip&下载jupyter lab

Embedded software development written examination and interview notes (latest update: February 17, 2022)

Render values to corresponding text

美创入选“2022 CCIA中国网络安全竞争力50强”榜单
随机推荐
Service charge and time setting code sharing involved in crmeb withdrawal process
更新pip&下载jupyter lab
The amount is verified, and two zeros are spliced by integers during echo
GPS receiver design (1)
PHP files running online
PPT绘论文图之导出分辨率
按权重随机选择[前缀和+二分+随机target]
Lighten the source code -- lighten the app system development function introduction to the beautiful world lighten the app system development source code in China
2021-09-30
node. JS architecture optimization: reverse proxy and cache service
Write regular isosceles triangle and inverse isosceles triangle with for loop in JS
Optimal solution for cold start
Happy shopkeeper source code -- Introduction to happy shopkeeper system development mode
JS function exercises
Why are databases cloud native?
Laravel task scheduling
Render values to corresponding text
20220620 面试复盘
Penetration tool environment - installing sqli labs in centos7 environment
GNSS receiver technology and application review