当前位置:网站首页>The practice of the beego framework of goweb development: Section II project initialization configuration
The practice of the beego framework of goweb development: Section II project initialization configuration
2022-07-28 17:20:00 【qfliweimin】
One 、Beego Project organization structure
The content of the last lesson is right beego A simple analysis of the case code of , To sum up beego Organizational structure of the project , Summarized below :
- conf: The directory where the project configuration file is located , Some global configurations in the project can be placed in this directory . default app.conf Three configurations are specified by default in the file :
- 1)appname = BeegoDemo2: Specify project name .
- 2)httpport = 8080: Specify the project service listening port .
- 3)runmode = dev: Specify the execution mode .
- controllers: This directory is the directory where the controller files are stored , The so-called controller is to control which business logic the application calls , from controllers processed http After the request , And be responsible for returning to the front-end caller .
- models:models Layer can be interpreted as entity layer or data layer , stay models The layer realizes the processing of user and business data , Some operations related to database tables will be implemented in this directory , Then return the executed result data to controller layer . For example, insert new data into the database , Delete database table data , Modify a piece of data , Querying business data from the database is in models Layer implementation .
- routers: This layer is the routing layer . Routing means distribution , The current browser performs a http The request reaches the background web Project time , It must be able to make the program according to the request of the browser url Different business processes , From receiving the front-end request to judging the process of executing specific business logic , Just from routers To achieve .
- static: stay static Under the table of contents , Deposit is web Static resource file of the project , There are mainly :css file ,img,js,html These kinds of documents .html The static page file of the application will be stored in .
- views:views What is stored in is stored in the application html Directory of template page . The so-called template , That is, the page frame and layout have been used html It's written , Just visit and show , Dynamically fill the obtained data into the page , It can improve rendering efficiency . therefore , Template file is a very common way .
Sum up , The whole project architecture is MVC The mode of operation of . You should be familiar with common architectural patterns, such as :MVC,MVP,MVVM And so on . Here we use MVC, It's clear and easy to understand .
Two 、 Routing settings
stay beego In the frame , Four routing settings are supported , They are : Basic routing , Fixed route , Regular routing and Automatic routing .
- 1、 Basic routing :
Directly through beego.Get,beego.POST,beego.Head,beego.Delete And other methods to map routes , Let's show you through code . We know , common http Request method operations include :GET,HEAD,PUT,POST,DELETE,OPTIONS etc. . 1. The first is basic GET route . Let's show you an example .beego.GET("",func) 2. The basis of POSt route :beego.POST("",func) 3. besides , And support Patch,Head,Delete Equal basic routing .
The above request and the corresponding way to find the request method type is RESTful form , What we use most is RESTful form RESTful It is currently developed API A form very commonly used in , In fact, that is RESTful The form is that the user is get Automatically execute when requested Get Method ,Post The request is executed Post Method .
- 2、 Fixed route : Code forms such as the following :
beego.Router("/",controller);
Get The request will correspond to Get Method ,Post Will correspond to Post Method ,Delete Will correspond to Delete Method ,Header The method will correspond to Header Method . - 3、 Regular routing : Regular routing refers to the ability to perform fixed routing , Support regular expressions that match a certain format . such as :id,:username, Custom regular ,file Path and suffix switching and full matching .
- 4、 Custom routing The above two routes are default, depending on the type of request ,Get Is executed Get Method ,Post perform Post Method , More limited . Because most of them use fixed matching when developing, they want to directly execute the corresponding logic control methods , therefore beego It provides us with customized routing configuration that can be customized . The way is as follows :
beego.Router("/",&IndexController{},"")It can be used HTTP Method:
- "*": Contains all of the following functions
- "get":GET request
- "post":POST request
- "put":PUT request
- "delete":DELETE request
- "patch":PATCH request
- "options":OPTIONS request
- "head":HEAD request
The above corresponding request methods , stay beego.Controller in , A lot of methods are defined , such as Init,Prepare,Post,Get,Head,Delete Other methods . The above analysis is beego Framework of the Router as well as Controller Running logic .
3、 ... and 、model Layer analysis
stay Web Development process , Developers manipulate data , The most common way to store data is database operation , Database operation is an independent module , This will be implemented in the following specific projects .
Four 、view To write
The actual combat projects here are static html Template files and other static resources , It has been written and provided to developers, which can be directly used in the project . In the actual development process , We need to master html,js Grammar and simple css Grammar should be able to understand , Be able to use time simply . More complex front-end pages or static pages , Need to dock with front-end developers . The development focus is on the background server , therefore , Just learn to use and call debugging .
5、 ... and 、 Static file settings
stay goweb In the project , As mentioned above, there are some static resource files , If the user wants to access the static resource file , We should also be able to visit , This requires static resource settings in our project . Set as :
beego.SetStaticPath("/down1","download1")there download Directory refers to non goweb Project static Under the directory , It's a new directory created by the developer .
6、 ... and 、 Introduction to actual combat projects
In this series of courses , We use it together Beego Framework development to achieve a blog system . As shown in the figure below :




边栏推荐
- MySQL installation tutorial
- 线性代数及矩阵论(八)
- Some notes on how unity objects move
- Goweb开发之Beego框架实战:第三节 程序执行流程分析
- Unity shader uses rendered texture to achieve glass effect
- Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
- 创建自定义分页控件
- How do we do full link grayscale on the database?
- The 16th program design competition of Dalian University of Technology (Problem Solver)
- What does the service grid that has been popular for two years bring to microservices? (Reprinted)
猜你喜欢

influxdb2的使用

Message Passing for Complex Question Answering over Knowledge Graphs

Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr

Goweb开发之Beego框架实战:第四节 数据库配置及连接

我为什么选择使用Go语言?

22年多校第三场(F的证明

Games101 assignment04 job 04

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

Games101-assignment05 ray tracing - rays intersect triangles

Ugui learning notes (II) Scrollview related
随机推荐
Unity shader texture animation
: No such file or directory
Reasoning Over Semantic-Level Graph for Fact Checking
Atcoder beginer contest 240 g.reporting Takahashi (classical problems of Combinatorial Mathematics)
Unity shader screen post-processing
HTAP comes at a price
Codeforces round 770 (Div. 2) e. fair share
Goweb开发之Beego框架实战:第二节 项目初始化配置
DGL Chapter 1 (official tutorial) personal notes
部分情况下Error:(xx, xx) Failed to resolve: xxxxxx解决。
Reduce cycle complexity
Mysql database addition, deletion, modification and query (detailed explanation of basic operation commands)
Use of influxdb2
Classroom attendance system based on QT design (using RDS for MySQL cloud database)
Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
Hikvision responded to the impact of the 'US ban': there are options for the components currently used
Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
System clock failure of database fault tolerance
《Kubernetes》你需要掌握的 Service 和 Ingress
零基础利用Unity3D开发AR应用并远程下载3D模型