Introduction
beego official is defined as a Go thinking of using to help you build and develop open-source framework Go application.
beego framework has some of the following features:
-
simplify
RESTful support, MVC model, you can use the bee tools to quickly develop applications, including monitoring heat compile code modification, automation and automated test code package deployment.
-
Intelligent
Support intelligent routing, intelligent monitoring, you can monitor QPS, memory consumption, CPU usage, and operating conditions goroutine to make your online application under control.
-
Modular
beego built a powerful module, including the Session, cache operations, logging, parsing the configuration, performance monitoring, context operation, the ORM block, powerful module request simulation, sufficient to support any of your application.
-
high performance
Go beego using native http package to handle the request, goroutine concurrent efficiency sufficient to meet the API Web applications and large flow applications, has been used in a large number of highly concurrent products.
installation
Note that before installing beego framework should first GOPATH configured, if you are a novice, the proposed closure go mod, this can reduce the difficulty of installation.
If you are a windows operating system, you need to install git. Click here to download and install.
Installation beego framework need to go get command to install.
go get github.com/astaxie/beego
If the project needs to be upgraded beego, there are two ways to choose:
The first is the official recommended way to upgrade through go get command.
go get -u github.com/astaxie/beego
The second way is to download the source code covered by the previous source way to upgrade ( click to download the source code ). After downloading the source code, the source code to cover $GOPATH/src/github.com/astaxie/beego
directory, execute the following command to complete the upgrade.
go install github.com/astaxie/beego
Installation bee tools
The main role of bee tools to assist project development beego be go through the bee, can achieve the creation of beego project, hot compilation, development, testing and deployment.
bee tool can be installed by the following command:
go get github.com/beego/bee
By default, bee executable files are stored in GOPATH/bin
the directory.
The official suggested
$GOPATH/bin
directory configuration variables which go into the environment. If you have not configured accordingly, you can conduct its own Baidu depending on the operating system, if you do not configure this, you will not be able to use the follow-up.
bee commonly used commands
Specific use can enter the official website to view .
new command
Can quickly create new commands through a beego project, but use this command to switch to the directory should be $GOPATH/src
under execution, the project will eventually generate the following structure:
bee new myproject
[INFO] Creating application...
/gopath/src/myproject/
/gopath/src/myproject/conf/
/gopath/src/myproject/controllers/
/gopath/src/myproject/models/
/gopath/src/myproject/static/
/gopath/src/myproject/static/js/
/gopath/src/myproject/static/css/
/gopath/src/myproject/static/img/
/gopath/src/myproject/views/
/gopath/src/myproject/conf/app.conf
/gopath/src/myproject/controllers/default.go
/gopath/src/myproject/views/index.tpl
/gopath/src/myproject/main.go
13-11-25 09:50:39 [SUCC] New application successfully created!
myproject
├── conf
│ └── app.conf
├── controllers
│ └── default.go
├── main.go
├── models
├── routers
│ └── router.go
├── static
│ ├── css
│ ├── img
│ └── js
├── tests
│ └── default_test.go
└── views
└── index.tpl
8 directories, 4 files
api command
You can quickly create an application through api api command. as follows:
bee api apiproject
create app folder: /gopath/src/apiproject
create conf: /gopath/src/apiproject/conf
create controllers: /gopath/src/apiproject/controllers
create models: /gopath/src/apiproject/models
create tests: /gopath/src/apiproject/tests
create conf app.conf: /gopath/src/apiproject/conf/app.conf
create controllers default.go: /gopath/src/apiproject/controllers/default.go
create tests default.go: /gopath/src/apiproject/tests/default_test.go
create models object.go: /gopath/src/apiproject/models/object.go
create main.go: /gopath/src/apiproject/main.go
apiproject
├── conf
│ └── app.conf
├── controllers
│ └── object.go
│ └── user.go
├── docs
│ └── doc.go
├── main.go
├── models
│ └── object.go
│ └── user.go
├── routers
│ └── router.go
└── tests
└── default_test.go
The command also supports some custom parameters to automatically connect to the database to create a relevant model and controller:
bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]
If the parameter is empty conn create a sample project, otherwise it will create a project based on the link information database.
run the command
Our biggest problem in the development of the project when Go is often required to manually compile their own run, bee run
the command is monitoring beego project, by fsnotify monitor file system. However, note that the command must be $GOPATH/src/appname
executed under.
In the development process so that we can see in real time the effect of the project after the modification:
bee run
13-11-25 09:53:04 [INFO] Uses 'myproject' as 'appname'
13-11-25 09:53:04 [INFO] Initializing watcher...
13-11-25 09:53:04 [TRAC] Directory(/gopath/src/myproject/controllers)
13-11-25 09:53:04 [TRAC] Directory(/gopath/src/myproject/models)
13-11-25 09:53:04 [TRAC] Directory(/gopath/src/myproject)
13-11-25 09:53:04 [INFO] Start building...
13-11-25 09:53:16 [SUCC] Build was successful
13-11-25 09:53:16 [INFO] Restarting myproject ...
13-11-25 09:53:16 [INFO] ./myproject is running...
We open the browser can see the effect http://localhost:8080/
, will be showing a beego welcome page.