当前位置:网站首页>The actual combat of the beego framework of goweb development: Section III program execution process analysis
The actual combat of the beego framework of goweb development: Section III program execution process analysis
2022-07-28 17:20:00 【qfliweimin】
Perform process analysis
Go When a language executes, it executes main Under the bag init function ,main Function in turn . therefore , First find main.go file .

As shown above main.go The contents of the document , So how does the code execute ? First ,import Imported two packages , One is routers, One is beego. And in the routers In front of the bag , You can see there's one “_”, This indicates the introduction of routers package , And implement init Method . Here is a knowledge point , Namely Go The execution of language , Here is a program execution flow chart :

According to the picture above , We can know that the program first arrives at routers Package execution init Method . To router.go Take a look at the specific code :

You can see in the router.go There's one in the file init Method , notice beego.Router() This code .router It means routing , The function of this function is to map URL To controller, The first parameter is URL ( The address requested by the user ), It's registered here /, That is, access without any parameters URL, The second parameter corresponds to Controller, The request will be distributed to that controller to execute the corresponding logic , Now go here and set up MainController Go and see what method there is :

MainController Structures and functions are declared in default.go In file . And here's one Get Method , There are three lines of code in the method .
Accessed in the browser above is :http://localhost:8080, This is a get request , When the request goes backstage , There are no request parameters , therefore , Will be “/” Intercept , Execute to MainController The code in , the reason being that get request , So here we automatically find Get Function and execute .
stay get In the function , There are three codes , The first two sentences c.Data[]= "" Indicates the data fields and contents returned by setting , The last sentence c.TplName Indicates that the setting handles the request and points to a template file , It points to index.tpl, that index.tpl Where are the documents ? You can view the project directory structure , stay views below ,views Here are some template files .
- Template file
A brief explanation , Most pages are static html+css+js Wait for these static code to layout the page , Page effect control, etc , The data of the page is represented by variables , such , When displaying the page , It can automatically fill in the value of the variable in the page ; These static code files are collectively referred to as template files . Each template file is just like a template , The style and effect are fixed , Just render and display according to different data .
beego.Run() Logic
init After the method analysis , The program will continue to run down , That's it main function , stay main Execute in function :beego.Run() Code . Look at the Run Logic of code , stay Run Methods the internal , I did a few things :
- 1) Parse configuration file , That's our app.conf file , Like ports , Application name and other information .
- 2) Check if it's on session, If open session, It initializes a session object .
- 3) Whether to compile templates ,beego When the project starts, the framework will change the configuration according to the configuration views All templates in the directory are precompiled , Then store it in map in , This can effectively improve the efficiency of template operation , There is no need to compile multiple times .
- 4) Listen to the service port . according to app.conf Port configuration in file , Start listening .
边栏推荐
- What does the service grid that has been popular for two years bring to microservices? (Reprinted)
- Unity editor learning (I) using features to change the display of fields in components
- Source code of voice live broadcast app
- Games101-assignment05 ray tracing - rays intersect triangles
- Function接口之andThen
- Differences between CNSA and CASC and CASIC
- Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
- [deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
- wpf命令按钮透明样式
- The maximum recommended number of rows for MySQL is 2000W. Is it reliable?
猜你喜欢

线性代数及矩阵论(九)

飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
![[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)

Classroom attendance system based on QT design (using RDS for MySQL cloud database)

What does the service grid that has been popular for two years bring to microservices? (Reprinted)

微服务架构-服务注册中心和服务网关(6.8) (转载)

零基础利用Unity3D开发AR应用并远程下载3D模型

Unity shader procedural texture

Unity editor learning (I) using features to change the display of fields in components
![[deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)
随机推荐
充分利用----英文
kubernetes service 原理解析
火了 2 年的服务网格究竟给微服务带来了什么?(转载)
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
Ugui learning notes (III) summary of the use of each control
Create a self-organizing / safe / controllable Lora network! Semtech responded for the first time to the impact of the "new regulations of the Ministry of industry and information technology"
Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
Technology sharing | how to recover the erroneously deleted table and the data in the table?
The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
带参数的微信小程序二维码生成
Deep understanding of deepsea and salt deployment tools – storage6
Add differential pairs and connections in Ad
Easypoi --- excel file export
Fine-grained Fact Verification with Kernel GA Network
Question making note 3 (two point search)
How to protect image security during construction
: No such file or directory
Codeforces round 770 (Div. 2) e. fair share
Vscode界面介绍
Visual Studio 2012/2015发布Web应用连同.cs源码一起发布