name: Create a new project

sort: 1

Requirements

Before starting any Beego project make sure that you have installed the bee tool and the beego package. If you don’t have them yet please read Installing beego and Installing bee tool before you proceed.

Creating a new project

Create a new Beego project with the bee command.

Open a terminal to your $GOPATH directory and enter bee new quickstart:

  1. src bee new quickstart
  2. [INFO] Creating application...
  3. /gopath/src/quickstart/
  4. /gopath/src/quickstart/conf/
  5. /gopath/src/quickstart/controllers/
  6. /gopath/src/quickstart/models/
  7. /gopath/src/quickstart/routers/
  8. /gopath/src/quickstart/tests/
  9. /gopath/src/quickstart/static/
  10. /gopath/src/quickstart/static/js/
  11. /gopath/src/quickstart/static/css/
  12. /gopath/src/quickstart/static/img/
  13. /gopath/src/quickstart/views/
  14. /gopath/src/quickstart/conf/app.conf
  15. /gopath/src/quickstart/controllers/default.go
  16. /gopath/src/quickstart/views/index.tpl
  17. /gopath/src/quickstart/routers/router.go
  18. /gopath/src/quickstart/tests/default_test.go
  19. 2015/05/02 11:55:28 [SUCC] New application successfully created!

The bee tool has created a new Beego project with the following structure:

  1. quickstart
  2. ├── conf
  3. └── app.conf
  4. ├── controllers
  5. └── default.go
  6. ├── main.go
  7. ├── models
  8. ├── routers
  9. └── router.go
  10. ├── static
  11. ├── css
  12. ├── img
  13. └── js
  14. ├── tests
  15. └── default_test.go
  16. └── views
  17. └── index.tpl

This is a typical MVC application and main.go is the project’s main file.

Running project

Go to the path of the newly created project and enter bee run to compile and run the project.

  1. src cd quickstart
  2. quickstart bee run
  3. 2015/05/02 12:01:31 [INFO] Uses 'quickstart' as 'appname'
  4. 2015/05/02 12:01:31 [INFO] Initializing watcher...
  5. 2015/05/02 12:01:31 [TRAC] Directory(/gopath/src/quickstart/controllers)
  6. 2015/05/02 12:01:31 [TRAC] Directory(/gopath/src/quickstart)
  7. 2015/05/02 12:01:31 [TRAC] Directory(/gopath/src/quickstart/routers)
  8. 2015/05/02 12:01:31 [TRAC] Directory(/gopath/src/quickstart/tests)
  9. 2015/05/02 12:01:31 [INFO] Start building...
  10. 2015/05/02 12:01:36 [SUCC] Build was successful
  11. 2015/05/02 12:01:36 [INFO] Restarting quickstart ...
  12. 2015/05/02 12:01:36 [INFO] ./quickstart is running...
  13. 2015/05/02 12:01:38 [app.go:103] [I] http server Running on :8080

The web application will run on the default Beego port 8080. All of this has been accomplished using only Go and Beego, without the need for nginx or apache. Let’s look at our application in the browser now:

Requirements - 图1

Beego makes it so easy to create a web application! Let’s dive into the project now and see how everything works in the next section.