Introduction to the MVC architecture of Beego

Source: Internet
Author: User

Introduction to the MVC architecture of Beego

Beego is a typical MVC framework, and its entire execution logic looks like this:

The words are described as follows:

  1. The listening port receives the data, and the default listener is on port 8080.
  2. A user request arrives at port 8080 and then enters Beego's processing logic.
  3. Initializes the Context object, determines whether the request is a WebSocket request, if so, sets Input, and determines whether the requested method is in the standard request method ("Get" "post" "Put" "Delete" "Patch" "Options" "Head") to prevent unwanted tampering of a user's malicious forgery request attack.
  4. Implement Beforerouter filter, of course, there are switch settings in Beego. If the user has a filter set, the switch is turned on, which can improve execution efficiency without the filter turned on. If the responsewriter already has data output during the execution of the filter, the request is terminated ahead of time and jumps directly to the monitoring judgment.
  5. Begins the processing of the static file to see if the user's request URL matches the prefix registered in the static file processing Staticdir. If so, use the http default Servefile in the package to handle the static files.
  6. If it is not a static file to start initializing the session module (if you open the session), this inside people need to note that if your beforerouter filter to the session will be error, you should add to the afterstatic filter.
  7. Start the execution of the afterstatic filter, if in the execution of the filter process, Responsewriter already have data output, then the early end of the request, jump directly to the monitoring judgment.
  8. After the filter has been executed, the object that matches the URL is started to be found and requested from a fixed routing rule. This match is a full match rule, that is, if the URL requested by the user is /hello/world , then the fixed rule /hello is not matched, only the exact match is counted. If the match goes into logical execution, if it does not match the regular match into the next link.
  9. Regular matching is the full match of the regular match, which is matched according to the user's added Beego routing order, that is, if you add the route, your order will affect your match. As with a fixed match, if the match is executed logically, if the mismatch goes into Auto match.
  10. If the user registers the Autorouter, then controller/method this way will find the corresponding Controller and his built-in method, if found to start the execution of logic, if not found to jump to the monitoring judgment.
  11. If the Controller is found, then start to execute the logic, first execute the beforeexec filter, if in the execution of the filter process, Responsewriter already has data output, then the early end of the request, jump directly to the monitoring judgment.
  12. The Controller starts executing the Init function and initializes some basic information, which is generally beego. Controller initialization, it is not recommended to modify the function when the user inherits.
  13. If XSRF is turned on, the Controller's Xsrftoken is invoked, and then the Checkxsrfcookie method is called if it is a POST request.
  14. Continue to execute the controller's Prepare function, which is usually reserved for the user, to do some of the parameters in the controller initialization and other work. If the output is responsewriter in the initialization, it goes directly to the Finish function logic.
  15. If there is no output, then according to the user registration method to execute the corresponding logic, if the user is not registered, then call HTTP. Method (Get/post, etc.). Execute the appropriate logic, such as data reading, data assignment, template display, or direct output of JSON or XML.
  16. If the responsewriter does not have output, then call the Render function for the template output.
  17. Executes the Controller's Finish function, which is reserved for use by the user to override, freeing up some resources. Releases the information data initialized in Init.
  18. Executes the afterexec filter and, if there is output, jumps to the monitoring judgment logic.
  19. Executes the destructor of the Controller to release some of the data initialized in Init.
  20. If the route is not found on this path, then 404 will be called to show that the page cannot be found.
  21. Finally all the logic is gathered to monitor the judgment, if the user turned on the monitoring module (by default, open a 8088 port for in-process monitoring), so that the access to the request link to the monitoring program to record the current access to the QPS, the corresponding link access execution time, request links and so on.

Introduction to the MVC architecture of Beego

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.