<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">(window.webpackJsonp=window.webpackJsonp||[]).push([[29],{292:function(e,t,o){e.exports=o.p+"assets/img/beerun.a4281e52.png"},469:function(e,t,o){"use strict";o.r(t);var a=o(14),n=Object(a.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h1",{attrs:{id:"introduction-to-bee-tool"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#introduction-to-bee-tool"}},[e._v("#")]),e._v(" Introduction to bee tool")]),e._v(" "),t("p",[e._v("Bee tool is a project for rapid Beego development. With bee tool developers can create, auto compile and reload, develop, test, and deploy Beego applications quickly and easily.")]),e._v(" "),t("h2",{attrs:{id:"installing-bee-tool"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#installing-bee-tool"}},[e._v("#")]),e._v(" Installing bee tool")]),e._v(" "),t("p",[e._v("Install bee tool with the following command:")]),e._v(" "),t("p",[t("code",[e._v("go get github.com/beego/bee/v2@latest")])]),e._v(" "),t("p",[e._v("Update the bee tool with the following command:")]),e._v(" "),t("p",[t("code",[e._v("go get -u github.com/beego/bee/v2@latest")])]),e._v(" "),t("p",[t("code",[e._v("bee")]),e._v(" is installed into "),t("code",[e._v("GOPATH/bin")]),e._v(" by default. You need to add "),t("code",[e._v("GOPATH/bin")]),e._v(" to your PATH, otherwise the "),t("code",[e._v("bee")]),e._v(" command won't work.")]),e._v(" "),t("p",[e._v("More details in "),t("RouterLink",{attrs:{to:"/en-US/v2.1.x/bee/env.html"}},[e._v("bee installation")])],1),e._v(" "),t("h2",{attrs:{id:"bee-tool-commands"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#bee-tool-commands"}},[e._v("#")]),e._v(" bee tool commands")]),e._v(" "),t("p",[e._v("Type "),t("code",[e._v("bee")]),e._v(" in command line and the following messages with be displayed:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("bee is a tool for managing Beego framework.\n\nUsage:\n\n\tbee command [arguments]\n\nThe commands are:\n\n\tnew         Create a Beego application\n\trun         run the app and start a Web server for development\n\tpack        Compress a Beego project into a single file\n\tapi         create an API Beego application\n\tbale        packs non-Go files to Go source files\n\tversion     show the bee, Beego and Go version\n\tgenerate    source code generator\n\tmigrate     run database migrations\n")])])]),t("h3",{attrs:{id:"command-new"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-new"}},[e._v("#")]),e._v(" Command new")]),e._v(" "),t("p",[e._v("The "),t("code",[e._v("new")]),e._v(" command can create a new web project. You can create a new Beego project by typing "),t("code",[e._v("bee new &lt;project name&gt;")]),e._v(" under "),t("code",[e._v("$GOPATH/src")]),e._v(". This will generate all the default project folders and files:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("bee new myproject\n[INFO] Creating application...\n/gopath/src/myproject/\n/gopath/src/myproject/conf/\n/gopath/src/myproject/controllers/\n/gopath/src/myproject/models/\n/gopath/src/myproject/static/\n/gopath/src/myproject/static/js/\n/gopath/src/myproject/static/css/\n/gopath/src/myproject/static/img/\n/gopath/src/myproject/views/\n/gopath/src/myproject/conf/app.conf\n/gopath/src/myproject/controllers/default.go\n/gopath/src/myproject/views/index.tpl\n/gopath/src/myproject/main.go\n13-11-25 09:50:39 [SUCC] New application successfully created!\n")])])]),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("myproject\nâ”œâ”€â”€ conf\nâ”‚Â&nbsp;Â&nbsp; â””â”€â”€ app.conf\nâ”œâ”€â”€ controllers\nâ”‚Â&nbsp;Â&nbsp; â””â”€â”€ default.go\nâ”œâ”€â”€ main.go\nâ”œâ”€â”€ models\nâ”œâ”€â”€ routers\nâ”‚Â&nbsp;Â&nbsp; â””â”€â”€ router.go\nâ”œâ”€â”€ static\nâ”‚Â&nbsp;Â&nbsp; â”œâ”€â”€ css\nâ”‚Â&nbsp;Â&nbsp; â”œâ”€â”€ img\nâ”‚Â&nbsp;Â&nbsp; â””â”€â”€ js\nâ”œâ”€â”€ tests\nâ”‚Â&nbsp;Â&nbsp; â””â”€â”€ default_test.go\nâ””â”€â”€ views\n    â””â”€â”€ index.tpl\n\n8 directories, 4 files\n")])])]),t("h3",{attrs:{id:"command-api"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-api"}},[e._v("#")]),e._v(" Command api")]),e._v(" "),t("p",[e._v("The "),t("code",[e._v("new")]),e._v(" command is used for crafting new web applications. The "),t("code",[e._v("api")]),e._v(" command is used to create new API applications.\nHere is the result of running "),t("code",[e._v("bee api project_name")]),e._v(":")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("bee api apiproject\ncreate app folder: /gopath/src/apiproject\ncreate conf: /gopath/src/apiproject/conf\ncreate controllers: /gopath/src/apiproject/controllers\ncreate models: /gopath/src/apiproject/models\ncreate tests: /gopath/src/apiproject/tests\ncreate conf app.conf: /gopath/src/apiproject/conf/app.conf\ncreate controllers default.go: /gopath/src/apiproject/controllers/default.go\ncreate tests default.go: /gopath/src/apiproject/tests/default_test.go\ncreate models object.go: /gopath/src/apiproject/models/object.go\ncreate main.go: /gopath/src/apiproject/main.go\n")])])]),t("p",[e._v("Below is the generated project structure of a new API application:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("apiproject\nâ”œâ”€â”€ conf\nâ”‚   â””â”€â”€ app.conf\nâ”œâ”€â”€ controllers\nâ”‚   â””â”€â”€ object.go\nâ”‚   â””â”€â”€ user.go\nâ”œâ”€â”€ docs\nâ”‚   â””â”€â”€ doc.go\nâ”œâ”€â”€ main.go\nâ”œâ”€â”€ models\nâ”‚   â””â”€â”€ object.go\nâ”‚   â””â”€â”€ user.go\nâ”œâ”€â”€ routers\nâ”‚   â””â”€â”€ router.go\nâ””â”€â”€ tests\n    â””â”€â”€ default_test.go\n")])])]),t("p",[e._v("Compare this to the "),t("code",[e._v("bee new myproject")]),e._v(" command seen earlier.\nNote that the new API application doesn't have a "),t("code",[e._v("static")]),e._v(" and "),t("code",[e._v("views")]),e._v(" folder.")]),e._v(" "),t("p",[e._v("You can also create a model and controller based on the database schema by providing database conn:")]),e._v(" "),t("p",[t("code",[e._v('bee api [appname] [-tables=""] [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/test]')])]),e._v(" "),t("h3",{attrs:{id:"command-run"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-run"}},[e._v("#")]),e._v(" Command run")]),e._v(" "),t("p",[e._v("The "),t("code",[e._v("bee run")]),e._v(" command will supervise the file system of any Beego project using "),t("a",{attrs:{href:"http://en.wikipedia.org/wiki/Inotify",target:"_blank",rel:"noopener noreferrer"}},[e._v("inotify"),t("OutboundLink")],1),e._v(".  The results will autocompile and display immediately after any modification in the Beego project folders.")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("13-11-25 09:53:04 [INFO] Uses 'myproject' as 'appname'\n13-11-25 09:53:04 [INFO] Initializing watcher...\n13-11-25 09:53:04 [TRAC] Directory(/gopath/src/myproject/controllers)\n13-11-25 09:53:04 [TRAC] Directory(/gopath/src/myproject/models)\n13-11-25 09:53:04 [TRAC] Directory(/gopath/src/myproject)\n13-11-25 09:53:04 [INFO] Start building...\n13-11-25 09:53:16 [SUCC] Build was successful\n13-11-25 09:53:16 [INFO] Restarting myproject ...\n13-11-25 09:53:16 [INFO] ./myproject is running...\n")])])]),t("p",[e._v("Visting "),t("code",[e._v("http://localhost:8080/")]),e._v(" with a web browser will display your app running:")]),e._v(" "),t("p",[t("img",{attrs:{src:o(292),alt:""}})]),e._v(" "),t("p",[e._v("After modifying the "),t("code",[e._v("default.go")]),e._v(" file in the "),t("code",[e._v("controllers")]),e._v(" folder, the following output will be displayed in the command line:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v('13-11-25 10:11:20 [EVEN] "/gopath/src/myproject/controllers/default.go": DELETE|MODIFY\n13-11-25 10:11:20 [INFO] Start building...\n13-11-25 10:11:20 [SKIP] "/gopath/src/myproject/controllers/default.go": CREATE\n13-11-25 10:11:23 [SKIP] "/gopath/src/myproject/controllers/default.go": MODIFY\n13-11-25 10:11:23 [SUCC] Build was successful\n13-11-25 10:11:23 [INFO] Restarting myproject ...\n13-11-25 10:11:23 [INFO] ./myproject is running...\n')])])]),t("p",[e._v("Refresh the browser to show the results of the new modifications.")]),e._v(" "),t("h3",{attrs:{id:"command-pack"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-pack"}},[e._v("#")]),e._v(" Command pack")]),e._v(" "),t("p",[e._v("The "),t("code",[e._v("pack")]),e._v(" command is used to compress the project into a single file. The compressed file can be deployed by uploading and extracting the zip file to the server.")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("bee pack\napp path: /gopath/src/apiproject\nGOOS darwin GOARCH amd64\nbuild apiproject\nbuild success\nexclude prefix:\nexclude suffix: .go:.DS_Store:.tmp\nfile write to `/gopath/src/apiproject/apiproject.tar.gz`\n")])])]),t("p",[e._v("The compressed file will be in the project folder:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("rwxr-xr-x  1 astaxie  staff  8995376 11 25 22:46 apiproject\n-rw-r--r--  1 astaxie  staff  2240288 11 25 22:58 apiproject.tar.gz\ndrwxr-xr-x  3 astaxie  staff      102 11 25 22:31 conf\ndrwxr-xr-x  3 astaxie  staff      102 11 25 22:31 controllers\n-rw-r--r--  1 astaxie  staff      509 11 25 22:31 main.go\ndrwxr-xr-x  3 astaxie  staff      102 11 25 22:31 models\ndrwxr-xr-x  3 astaxie  staff      102 11 25 22:31 tests\n")])])]),t("h3",{attrs:{id:"command-bale"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-bale"}},[e._v("#")]),e._v(" Command bale")]),e._v(" "),t("p",[e._v("This command is currently only available to the developer team. It is used to compress all static files in to a single binary file so that they do not need to carry static files including js, css, images and views when publishing the project. Those files will be self-extracting with non-overwrite when the program starts.")]),e._v(" "),t("h3",{attrs:{id:"command-version"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-version"}},[e._v("#")]),e._v(" Command version")]),e._v(" "),t("p",[e._v("This command displays the version of "),t("code",[e._v("bee")]),e._v(", "),t("code",[e._v("beego")]),e._v(", and "),t("code",[e._v("go")]),e._v(".")]),e._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[e._v("$ bee version\nbee   :1.2.2\nBeego :1.4.2\nGo    :go version go1.3.3 darwin/amd64\n")])])]),t("p",[e._v("This command try to output beego's version. It works well for GOPATH mode. Bee finds beego's version from $GOPATH/src/astaxie/beego directory.")]),e._v(" "),t("p",[e._v("So when we use GOMOD mode, and we don't download beego's source code, Bee could not find the version's information.")]),e._v(" "),t("h3",{attrs:{id:"command-generate"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-generate"}},[e._v("#")]),e._v(" Command generate")]),e._v(" "),t("p",[e._v("This command will generate the routers by analyzing the functions in controllers.")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v('bee generate scaffold [scaffoldname] [-fields=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]\n    The generate scaffold command will do a number of things for you.\n    -fields: a list of table fields. Format: field:type, ...\n    -driver: [mysql | postgres | sqlite], the default is mysql\n    -conn:   the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test\n    example: bee generate scaffold post -fields="title:string,body:text"\n\nbee generate model [modelname] [-fields=""]\n    generate RESTful model based on fields\n    -fields: a list of table fields. Format: field:type, ...\n\nbee generate controller [controllerfile]\n    generate RESTful controllers\n\nbee generate view [viewpath]\n    generate CRUD view in viewpath\n\nbee generate migration [migrationfile] [-fields=""]\n    generate migration file for making database schema update\n    -fields: a list of table fields. Format: field:type, ...\n\nbee generate docs\n    generate swagger doc file\n    \nbee generate routers [-ctrlDir=/path/to/controller/directory] [-routersFile=/path/to/routers/file.go] [-routersPkg=myPackage]\n    -ctrlDir: the directory contains controllers definition. Bee scans this directory and its subdirectory to generate routers info\n    -routersFile: output file. All generated routers info will be output into this file. \n              If file not found, Bee create new one, or Bee truncates it.\n              The default value is "routers/commentRouters.go"\n    -routersPkg: package declaration.The default value is "routers". \n              When you pass routersFile parameter, you\'d better pass this parameter\n\nbee generate test [routerfile]\n    generate testcase\n\nbee generate appcode [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-level=3]\n    generate appcode based on an existing database\n    -tables: a list of table names separated by \',\', default is empty, indicating all tables\n    -driver: [mysql | postgres | sqlite], the default is mysql\n    -conn:   the connection string used by the driver.\n             default for mysql:    root:@tcp(127.0.0.1:3306)/test\n             default for postgres: postgres://postgres:postgres@127.0.0.1:5432/postgres\n    -level:  [1 | 2 | 3], 1 = models; 2 = models,controllers; 3 = models,controllers,router\n')])])]),t("h3",{attrs:{id:"command-migrate"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#command-migrate"}},[e._v("#")]),e._v(" Command migrate")]),e._v(" "),t("p",[e._v("This command will run database migration scripts.")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v('bee migrate [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]\n    run all outstanding migrations\n    -driver: [mysql | postgresql | sqlite], the default is mysql\n    -conn:   the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test\n\nbee migrate rollback [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]\n    rollback the last migration operation\n    -driver: [mysql | postgresql | sqlite], the default is mysql\n    -conn:   the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test\n\nbee migrate reset [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]\n    rollback all migrations\n    -driver: [mysql | postgresql | sqlite], the default is mysql\n    -conn:   the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test\n\nbee migrate refresh [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]\n    rollback all migrations and run them all again\n    -driver: [mysql | postgresql | sqlite], the default is mysql\n    -conn:   the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test\n')])])]),t("h2",{attrs:{id:"bee-tool-configuration"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#bee-tool-configuration"}},[e._v("#")]),e._v(" bee tool configuration")]),e._v(" "),t("p",[e._v("The file "),t("code",[e._v("bee.json")]),e._v(" in the bee tool source code folder is the Beego configuration file. This file is still under development, but some options are already available to use:")]),e._v(" "),t("ul",[t("li",[t("code",[e._v('"version": 0')]),e._v(": version of file, for checking incompatible format version.")]),e._v(" "),t("li",[t("code",[e._v('"go_install": false')]),e._v(": if you use a full import path like "),t("code",[e._v("github.com/user/repo/subpkg")]),e._v(" you can enable this option to run "),t("code",[e._v("go install")]),e._v(" and speed up you build processes.")]),e._v(" "),t("li",[t("code",[e._v('"watch_ext": []')]),e._v(": add other file extensions to watch (only watch "),t("code",[e._v(".go")]),e._v(" files by default). For example, "),t("code",[e._v(".ini")]),e._v(", "),t("code",[e._v(".conf")]),e._v(", etc.")]),e._v(" "),t("li",[t("code",[e._v('"dir_structure":{}')]),e._v(": if your folder names are not the same as MVC classic names you can use this option to change them.")]),e._v(" "),t("li",[t("code",[e._v('"cmd_args": []')]),e._v(": add command arguments for every start.")]),e._v(" "),t("li",[t("code",[e._v('"envs": []')]),e._v(": set environment variables for every start.")])])])}),[],!1,null,null,null);t.default=n.exports}}]);</pre></body></html>