Go language Beego Frame environment construction

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Beego is an open-source HTTP framework that uses go thinking to quickly build and develop a go application, the author of Xie Mengjun. It can quickly develop APIs, WEB, backend services and other applications, features support restful framework, MVC model, can use bee tools to quickly develop applications, including intelligent routing, built-in powerful modules, using the Go native HTTP packet to handle the request; Goroutine is easy to use and powerful because of the concurrency of the WEB applications and API applications that are large enough to handle high traffic.
Assuming that the go development environment has been set up, such as Go package installation, Gopath,goroot,gobin and other environment variables are OK. You can enter go version and go env in the CMD Command Line window to see if the settings are successful.

My Beego framework project is named Ocean,gopath=e:\work\ocean and the following steps are as follows (command line):
Attention:
The Gopath directory convention has three subdirectories:
1). SRC holds the source code (e.g.. Go. C. H. s, etc.);
2). pkg files generated after compilation (e.g.. a);
3). The executable file generated after bin compilation (this directory can be set to the Gobin variable and added to the environment variable.) If you have more than one gopath, use ${gopath//://bin:}/bin to add all the bin directories).

1. Install the Beego package (frame code package)
Open cmd, enter

get github.com/astaxie/beego

After the meeting, the go Get command will generate the Github.com folder in Gopath\src\, which already contains the Astaxie\beego folder path.

2. Install the Bee tool (Framework Builder tool)
Similarly, on the command line, enter

get github.com/astaxie/bee

The go get command will generate the Github.com folder in Gopath\src\, which already contains the Beego\bee folder path.

At the same time, in the SRC parallel directory, a bin folder is automatically generated, which contains the Bee.exe Framework Generation tool (note gobin to be added to the environment variables, such as Gobin=e:\work\ocean\bin).

3. Using the Bee tool to generate the framework code
Open cmd, enter "Bee New project Name" with "CD work\ocean\src" command into Gopath's SRC path

new ocean

The Bee framework code is generated in the Gopath\src folder, as shown in.

文件目录如下:ocean    ├── conf   |   └── app.conf├── controllers|    └── default.go├── main.go├── models├── routers   |    └── router.go├── static│   ├── css│   ├── img│   └── js├── tests│   └── default_test.go└── views        └── index.tpl

From the above directory structure we can see that the Beego file directory is a typical MVC pattern structure, M (models directory), V (views directory), C (controllers directory) structure, Main.go is a portal file.
PS: If the SRC folder is missing, then using "Bee new Ocean" will make an error, as shown in.

4. Operation
Open cmd, use the "CD" command to enter the Gopath src\ project path, such as "E:\work\ocean\src\ocean" input

run

OK, the program has successfully started and listens on port 8080. When you open your browser and enter http://localhost:8080/(http://127.0.0.1:8080), you will see the following screen. In addition, bee also monitors changes to the source files. If a change is detected, Bee will reload the application automatically.

Knowledge Development
1. Beego Architecture
Built on the basis of eight independent modules, Beego is a highly decoupled framework. When the design of the Beego is to consider the function of modular, even if the user does not apply Beego HTTP logic, but also can be used in these standalone modules, for example, you can use the cache module to do your caching logic, using the log module to record your operation information, Use the Config module to parse your files in various formats, so not just in beego development, your socket game development is also a useful module, which is why Beego is popular for a reason. If you have played Lego, you should know that a lot of high-level things are a piece of building blocks, and design beego, these modules are building blocks, high-level robot is beego. The functionality of these modules and how they are used will be described in a later document.

2. Beego Execution Logic
Beego is a typical MVC architecture, and his execution logic looks like this:

3. Beego file directory

文件目录如下:ocean    ├── conf   |   └── app.conf├── controllers|    └── default.go├── main.go├── models├── routers   |    └── router.go├── static│   ├── css│   ├── img│   └── js├── tests│   └── default_test.go└── views        └── index.tpl

From the above directory structure we can see the structure of M (models directory), V (views directory), C (Controllers directory), Main.go is a portal file.

Related Article

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.