当前位置:网站首页>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 .
边栏推荐
- valarray数值库学习
- Goweb开发之Beego框架实战:第一节 Beego框架介绍
- How do we do full link grayscale on the database?
- Global mobile communication base station market in 2019: Ericsson, Huawei and Nokia ranked in the top three
- Deep understanding of deepsea and salt deployment tools – storage6
- Classroom attendance system based on QT design (using RDS for MySQL cloud database)
- 线性代数及矩阵论(十)
- 线性代数及矩阵论(九)
- Function接口之andThen
- Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
猜你喜欢
![[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation](/img/4e/a41eee56fc0e8d3089f105bcb63155.png)
[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation

C# 导入Excel文件数据的几种方法

Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)

MySQL数据库增删改查(基础操作命令详解)

DGL Chapter 1 (official tutorial) personal notes

How do we do full link grayscale on the database?

WPF command button transparent style
![[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)

Realize the reset function of steering wheel UI with touch rotation and finger departure in unity

Message Passing for Complex Question Answering over Knowledge Graphs
随机推荐
Unity shader realizes mirror effect with rendered texture
Technology sharing | how to recover the erroneously deleted table and the data in the table?
Fine-grained Fact Verification with Kernel GA Network
After paying $1.8 billion in royalties to Qualcomm, Huawei reportedly ordered 120million chips from MediaTek! Official response
Rsync service deployment and parameter details
配置V530交换机步骤
Goweb开发之Beego框架实战:第三节 程序执行流程分析
微服务架构-服务注册中心和服务网关(6.8) (转载)
influxdb2的使用
Visual Studio 2015 团队开发之Azure DevOps篇
创建自定义分页控件
: No such file or directory
线性代数及矩阵论(七)
Problem solution of code heartstrings Junior Group (official competition) of Dalian University of Technology (Development Zone campus) in 2021
Use of influxdb2
Valarray Library Learning
valarray数值库学习
22年多校第三场(F的证明
Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
What does the service grid that has been popular for two years bring to microservices? (Reprinted)