当前位置:网站首页>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 .
边栏推荐
- Algorithm learning: leetcode interview question 09. implement queue with two stacks
- Application of Pegasus d200s UAV and airborne lidar in large-scale DEM construction
- PostgreSQL weekly news - July 20, 2022
- 侦察机与预警机的区别
- 堡垒机的作用
- Leetcode 2022.04.10 China Merchants Bank special competition D. store promotion (DP)
- C # traversal set
- Comprehensively design an oppe homepage -- page service part
- A total of 13billion flash and 400million MCU were shipped! In depth analysis of the three product lines of Zhaoyi innovation
- Unity shader realizes water wave effect with noise texture
猜你喜欢
![[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)

Source code of voice live broadcast app

Proof of the third scene (f) in 22 years

Educational codeforces round 126 (rated for Div. 2) f.teleporters (two sets and two points)

Analysis of browser decoding process

浏览器解码过程分析

Net framework

HTAP comes at a price

Comprehensively design an oppe homepage -- page service part

Unity shader uses rendered texture to achieve glass effect
随机推荐
Easypoi multi sheet export by template
Vscode界面介绍
Comprehensively design an oppe homepage -- after sales service of the page
PostgreSQL weekly news - July 20, 2022
飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
3D modeling tool Archicad 26 newly released
influxdb2的使用
线性代数及矩阵论(八)
Shopee code League 2022 - qualification round p3.connecting the numbers (segment tree / bipartite graph determination, to be discussed)
C# 导入Excel文件数据的几种方法
valarray数值库学习
How to use fail2ban to protect WordPress login page
Visual Studio 2015 团队开发之Azure DevOps篇
《Kubernetes》你需要掌握的 Service 和 Ingress
Games101 assignment04 job 04
Some notes on how unity objects move
Difference between reconnaissance aircraft and early warning aircraft
The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
Make full use of English
In 2020q2, shipments in the global tablet market soared by 26.1%: Huawei ranked third and Lenovo increased the most!