当前位置:网站首页>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 .
边栏推荐
- 22年多校第三场(F的证明
- Unity3d simple implementation of water surface shader
- Ugui learning notes (V) togglegroup makes multiple choice radio boxes
- Valarray Library Learning
- Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
- Unity shader cartoon style rendering
- : No such file or directory
- MySQL installation tutorial
- Verilog 每日一题(VL6 数据串转并电路)
- Differences between CNSA and CASC and CASIC
猜你喜欢
![[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)

Comprehensively design an oppe homepage -- after sales service of the page

高速电路中电容的选型和应用——详解

在android开发过程中遇到.sqlite文件处理
![[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)

Ugui learning notes (II) Scrollview related

valarray数值库学习

Net framework

PostgreSQL weekly news - July 20, 2022

Fine-grained Fact Verification with Kernel GA Network
随机推荐
Steps to configure V530 switch
Learn about service discovery in kubernetes
我为什么选择使用Go语言?
2021年4月份自考
Janus series article 3 API usage guide videoroom creating a new video room
mysql 最大建议行数2000w,靠谱吗?
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
Atcoder beginer contest 240 g.reporting Takahashi (classical problems of Combinatorial Mathematics)
堡垒机的作用
部分情况下Error:(xx, xx) Failed to resolve: xxxxxx解决。
线性代数及矩阵论(七)
UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)G. GCD cost on the tree
线性代数及矩阵论(八)
带参数的微信小程序二维码生成
[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)
Goweb开发之Beego框架实战:第三节 程序执行流程分析
MySQL installation tutorial
C # traversal set
在android开发过程中遇到.sqlite文件处理
高速电路中电阻的选择