Bee is a command-line tool facilitating development of Beego-based application.
To install or update bee use the go install command:
go install github.com/beego/bee/v2@latest
bee binary to PATH environment variable in your ~/.bashrc or ~/.bash_profile file:export PATH=$PATH:<your_main_gopath>/bin
To install bee use the go get command:
go get github.com/beego/bee/v2
If you already have
beeinstalled, updatingbeeis simple:
go get -u github.com/beego/bee/v2
Bee provides a variety of commands which can be helpful at various stages of development. The top level commands include:
version Prints the current Bee version
migrate Runs database migrations
api Creates a Beego API application
bale Transforms non-Go files to Go source files
fix Fixes your application by making it compatible with newer versions of Beego
pro Source code generator
dlv Start a debugging session using Delve
dockerize Generates a Dockerfile and docker-compose.yaml for your Beego application
generate Source code generator
hprose Creates an RPC application based on Hprose and Beego frameworks
new Creates a Beego application
pack Compresses a Beego application into a single file
rs Run customized scripts
run Run the application by starting a local development server
server serving static content over HTTP on port
update Update Bee
To display the current version of bee, beego and go installed on your machine:
$ bee version
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.4
├── Beego : 2.0.4
├── GoVersion : go1.14.1
├── GOOS : darwin
├── GOARCH : amd64
├── NumCPU : 4
├── GOPATH : /home/beeuser/.go
├── GOROOT : /usr/local/Cellar/go/1.14.1/libexec
├── Compiler : gc
└── Published : 2020-09-13
You can also change the output format using -o flag:
$ bee version -o json
{
"GoVersion": "go1.14.1",
"GOOS": "darwin",
"GOARCH": "amd64",
"NumCPU": 4,
"GOPATH": "/home/beeuser/.go",
"GOROOT": "/usr/local/Cellar/go/1.14.1/libexec",
"Compiler": "gc",
"BeeVersion": "2.0.4",
"BeegoVersion": "2.0.4",
"Published": "2020-09-13"
}
For more information on the usage, run bee help version.
To create a new Beego web application:
$ bee new my-web-app
2020/09/14 22:28:51 INFO ▶ 0001 generate new project support go modules.
2020/09/14 22:28:51 INFO ▶ 0002 Creating application...
create /Users/beeuser/learn/my-web-app/go.mod
create /Users/beeuser/learn/my-web-app/
create /Users/beeuser/learn/my-web-app/conf/
create /Users/beeuser/learn/my-web-app/controllers/
create /Users/beeuser/learn/my-web-app/models/
create /Users/beeuser/learn/my-web-app/routers/
create /Users/beeuser/learn/my-web-app/tests/
create /Users/beeuser/learn/my-web-app/static/
create /Users/beeuser/learn/my-web-app/static/js/
create /Users/beeuser/learn/my-web-app/static/css/
create /Users/beeuser/learn/my-web-app/static/img/
create /Users/beeuser/learn/my-web-app/views/
create /Users/beeuser/learn/my-web-app/conf/app.conf
create /Users/beeuser/learn/my-web-app/controllers/default.go
create /Users/beeuser/learn/my-web-app/views/index.tpl
create /Users/beeuser/learn/my-web-app/routers/router.go
create /Users/beeuser/learn/my-web-app/tests/default_test.go
create /Users/beeuser/learn/my-web-app/main.go
2020/09/14 22:28:51 SUCCESS ▶ 0003 New application successfully created!
For more information on the usage, run bee help new.
To run the application we just created, you can navigate to the application folder and execute:
$ cd my-web-app && bee run
For more information on the usage, run bee help run.
To compress a Beego application into a single deployable file:
$ bee pack
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.0
2016/12/26 22:29:29 INFO ▶ 0001 Packaging application on '/home/beeuser/.go/src/github.com/user/my-web-app'...
2016/12/26 22:29:29 INFO ▶ 0002 Building application...
2016/12/26 22:29:29 INFO ▶ 0003 Using: GOOS=linux GOARCH=amd64
2016/12/26 22:29:31 SUCCESS ▶ 0004 Build Successful!
2016/12/26 22:29:31 INFO ▶ 0005 Writing to output: /home/beeuser/.go/src/github.com/user/my-web-app/my-web-app.tar.gz
2016/12/26 22:29:31 INFO ▶ 0006 Excluding relpath prefix: .
2016/12/26 22:29:31 INFO ▶ 0007 Excluding relpath suffix: .go:.DS_Store:.tmp
2016/12/26 22:29:32 SUCCESS ▶ 0008 Application packed!
For more information on the usage, run bee help pack.
Inspired by makefile / npm scripts. Run script allows you to run arbitrary commands using Bee. Custom commands are provided from the "scripts" object inside bee.json or Beefile.
To run a custom command, use: $ bee rs mycmd ARGS
$ bee help rs
USAGE
bee rs
DESCRIPTION
Run script allows you to run arbitrary commands using Bee.
Custom commands are provided from the "scripts" object inside bee.json or Beefile.
To run a custom command, use: $ bee rs mycmd ARGS
AVAILABLE SCRIPTS
gtest
APP_ENV=test APP_CONF_PATH=$(pwd)/conf go test -v -cover
gtestall
APP_ENV=test APP_CONF_PATH=$(pwd)/conf go test -v -cover $(go list ./... | grep -v /vendor/)
Run your scripts with:
$ bee rs gtest tests/*.go
$ bee rs gtestall
To create a Beego API application:
$ bee api my-api
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.0
2020/09/14 22:35:11 INFO ▶ 0001 generate api project support go modules.
2020/09/14 22:35:11 INFO ▶ 0002 Creating API...
create /Users/beeuser/code/learn/my-api/go.mod
create /Users/beeuser/code/learn/my-api
create /Users/beeuser/code/learn/my-api/conf
create /Users/beeuser/code/learn/my-api/controllers
create /Users/beeuser/code/learn/my-api/tests
create /Users/beeuser/code/learn/my-api/conf/app.conf
create /Users/beeuser/code/learn/my-api/models
create /Users/beeuser/code/learn/my-api/routers/
create /Users/beeuser/code/learn/my-api/controllers/object.go
create /Users/beeuser/code/learn/my-api/controllers/user.go
create /Users/beeuser/code/learn/my-api/tests/default_test.go
create /Users/beeuser/code/learn/my-api/routers/router.go
create /Users/beeuser/code/learn/my-api/models/object.go
create /Users/beeuser/code/learn/my-api/models/user.go
create /Users/beeuser/code/learn/my-api/main.go
2020/09/14 22:35:11 SUCCESS ▶ 0003 New API successfully created!
For more information on the usage, run bee help api.
To create an Hprose RPC application based on Beego:
$ bee hprose my-rpc-app
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.0
2020/09/14 22:36:39 INFO ▶ 0001 generate api project support go modules.
2020/09/14 22:36:39 INFO ▶ 0002 Creating Hprose application...
create /Users/beeuser/code/learn/my-rpc-app/go.mod
create /Users/beeuser/code/learn/my-rpc-app
create /Users/beeuser/code/learn/my-rpc-app/conf
create /Users/beeuser/code/learn/my-rpc-app/conf/app.conf
create /Users/beeuser/code/learn/my-rpc-app/models
create /Users/beeuser/code/learn/my-rpc-app/models/object.go
create /Users/beeuser/code/learn/my-rpc-app/models/user.go
create /Users/beeuser/code/learn/my-rpc-app/main.go
2020/09/14 22:36:39 SUCCESS ▶ 0003 New Hprose application successfully created!
For more information on the usage, run bee help hprose.
To pack all the static files into Go source files:
$ bee bale
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.0
2020/09/14 22:37:56 SUCCESS ▶ 0001 Baled resources successfully!
For more information on the usage, run bee help bale.
For database migrations, use bee migrate.
For more information on the usage, run bee help migrate.
Bee also comes with a source code generator which speeds up the development.
For example, to generate a new controller named hello:
$ bee generate controller hello
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.0
2020/09/14 22:38:44 INFO ▶ 0001 Using 'Hello' as controller name
2020/09/14 22:38:44 INFO ▶ 0002 Using 'controllers' as package name
create /Users/beeuser/code/learn/my-api/controllers/hello.go
2020/09/14 22:38:44 SUCCESS ▶ 0003 Controller successfully generated!
For more information on the usage, run bee help generate.
Bee also helps you dockerize your Beego application by generating a Dockerfile and a docker-compose.yaml file.
For example, to generate a Dockerfile with golang:1.20.1 baseimage and exposing port 9000:
$ bee dockerize -baseimage=golang:1.20.1 -expose=9000
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.4
2023/05/02 21:03:05 INFO ▶ 0001 Generating Dockerfile and docker-compose.yaml...
2023/05/02 21:03:05 SUCCESS ▶ 0002 Dockerfile generated.
2023/05/02 21:03:05 SUCCESS ▶ 0003 docker-compose.yaml generated.
For more information on the usage, run bee help dockerize.
Bee can also help with debugging your application. To start a debugging session:
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.0
2020/09/14 22:40:12 INFO ▶ 0001 Starting Delve Debugger...
Type 'help' for list of commands.
(dlv) break main.main
Breakpoint 1 set at 0x40100f for main.main() ./main.go:8
(dlv) continue
> main.main() ./main.go:8 (hits goroutine(1):1 total:1) (PC: 0x40100f)
3: import (
4: _ "github.com/user/myapp/routers"
5: beego "github.com/beego/beego/v2/server/web"
6: )
7:
=> 8: func main() {
9: beego.Run()
10: }
11:
For more information on the usage, run bee help dlv.
To create a beegopro.toml file
$ bee pro toml
2020/09/14 22:51:18 SUCCESS ▶ 0001 Successfully created file beegopro.toml
2020/09/14 22:51:18 SUCCESS ▶ 0002 Toml successfully generated!
Source code generator by beegopro.toml
```bash $ bee pro gen 2020/09/14 23:01:13 INFO ▶ 0001 Create /Users/beeuser/.beego/beego-pro Success! 2020/09/14 23:01:13 INFO ▶ 0002 git pull /Users/beeuser/.beego/beego-pro 2020/09/14 23:01:15 INFO ▶ 0003 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0004 Using 'example' as package name from controllers 2020/09/14 23:01:15 INFO ▶ 0005 create file '/Users/beeuser/code/learn/my-web-app/controllers/bee_default_controller.go' from controllers 2020/09/14 23:01:15 INFO ▶ 0006 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0007 Using 'example' as package name from controllers 2020/09/14 23:01:15 INFO ▶ 0008 create file '/Users/beeuser/code/learn/my-web-app/controllers/example.go' from controllers 2020/09/14 23:01:15 INFO ▶ 0009 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0010 Using 'example' as package name from models 2020/09/14 23:01:15 INFO ▶ 0011 create file '/Users/beeuser/code/learn/my-web-app/models/bee_default_model.go' from models 2020/09/14 23:01:15 INFO ▶ 0012 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0013 Using 'example' as package name from models 2020/09/14 23:01:15 INFO ▶ 0014 create file '/Users/beeuser/code/learn/my-web-app/models/example.go' from models 2020/09/14 23:01:15 INFO ▶ 0015 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0016 Using 'example' as package name from routers 2020/09/14 23:01:15 INFO ▶ 0017 create file '/Users/beeuser/code/learn/my-web-app/routers/example.go' from routers 2020/09/14 23:01:15 INFO ▶ 0018 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0019 Using 'example' as package name from example 2020/09/14 23:01:15 INFO ▶ 0020 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/list.tsx' from example 2020/09/14 23:01:15 INFO ▶ 0021 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0022 Using 'example' as package name from example 2020/09/14 23:01:15 INFO ▶ 0023 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/formconfig.tsx' from example 2020/09/14 23:01:15 INFO ▶ 0024 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0025 Using 'example' as package name from example 2020/09/14 23:01:15 INFO ▶ 0026 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/create.tsx' from example 2020/09/14 23:01:15 INFO ▶ 0027 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0028 Using 'example' as package name from example 2020/09/14 23:01:15 INFO ▶ 0029 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/update.tsx' from example 2020/09/14 23:01:15 INFO ▶ 0030 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0031 Using 'example' as package name from example 2020/09/14 23:01:15 INFO ▶ 0032 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/info.tsx' from example 2020/09/14 23:01:15 INFO ▶ 0033 Using 'example' as name 2020/09/14 23:01:15 INFO ▶ 0034 Using 'example' as pac