当前位置:网站首页>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 :




边栏推荐
- 浏览器解码过程分析
- Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
- 批量下载文件
- The longest substring of sword finger offer without repeated characters
- Unity shader cartoon style rendering
- Comprehensively design an oppe homepage -- page service part
- 火了 2 年的服务网格究竟给微服务带来了什么?(转载)
- C # traversal set
- WPF command button transparent style
- Games101 assignment04 job 04
猜你喜欢

Fine-grained Fact Verification with Kernel GA Network

How to protect image security during construction

Mysql database addition, deletion, modification and query (detailed explanation of basic operation commands)

Games101 section 13 ray tracing notes

Re12: read these3 semantic self segmentation for abstract summary of long legal documents in low

微信小程序现金红包返回“IP地址非你在商户平台设置的可用IP地址”错误终极解决方法

Use of influxdb2

Goweb开发之Beego框架实战:第三节 程序执行流程分析

Easypoi --- excel file export

System clock failure of database fault tolerance
随机推荐
Valarray Library Learning
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
Using MVC in the UI of unity
Go language slow entry - process control statement
总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
PostgreSQL weekly news - July 20, 2022
Ugui learning notes (I) rendering level
堡垒机的作用
Verilog 每日一题 (VL5 信号发生器)
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)
Fine-grained Fact Verification with Kernel GA Network
Modeling Semantics with Gated Graph Neural Networks for KBQA
Unity shader global fog effect
飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
: No such file or directory
Verilog 每日一题(VL6 数据串转并电路)
Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)
Unity3d shader achieves ablation effect
火了 2 年的服务网格究竟给微服务带来了什么?(转载)