Beego框架入门
安装Beego框架的教程点这里。
安装完成后,我们新建一个名为helloword的Beego应用,运行如下脚本:
1 |
bee new helloword |
返回结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
______ | ___ \ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ \____/ \___| \___| v1.10.0 2020/04/24 08:32:42 WARN ▶ 0001 You current workdir is not inside $GOPATH/src. 2020/04/24 08:32:42 INFO ▶ 0002 Creating application... create /root/go/src/helloword/ create /root/go/src/helloword/conf/ create /root/go/src/helloword/controllers/ create /root/go/src/helloword/models/ create /root/go/src/helloword/routers/ create /root/go/src/helloword/tests/ create /root/go/src/helloword/static/ create /root/go/src/helloword/static/js/ create /root/go/src/helloword/static/css/ create /root/go/src/helloword/static/img/ create /root/go/src/helloword/views/ create /root/go/src/helloword/conf/app.conf create /root/go/src/helloword/controllers/default.go create /root/go/src/helloword/views/index.tpl create /root/go/src/helloword/routers/router.go create /root/go/src/helloword/tests/default_test.go create /root/go/src/helloword/main.go 2020/04/24 08:32:42 SUCCESS ▶ 0003 New application successfully created! |
说明helloword的Beego应用已经创建成功,我们切换到新应用目录下,可以看到自创创建如下文件夹及文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
conf #应用配置目录 --app.conf controllers #控制器目录 --default.go main.go #入口文件 models #模块目录 routers #路由目录 --router.go static #静态文件目录 --css --img --js tests --default_test.go views #模板目录 --index.tpl |
应用名称及运行端口都在conf/app.conf里,内容如下
1 2 3 |
appname = helloword #应用名称 httpport = 8080 #端口号 runmode = dev #运行模式 |
我们在应用目录(/root/go/src/helloword/)下执行下面脚本运行该应用:
1 |
bee run |
返回结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
______ | ___ \ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ \____/ \___| \___| v1.10.0 2020/04/24 08:55:10 INFO ▶ 0001 Using 'helloword' as 'appname' 2020/04/24 08:55:10 INFO ▶ 0002 Initializing watcher... helloword/controllers helloword/routers helloword 2020/04/24 08:55:12 SUCCESS ▶ 0003 Built Successfully! 2020/04/24 08:55:12 INFO ▶ 0004 Restarting 'helloword'... 2020/04/24 08:55:12 SUCCESS ▶ 0005 './helloword' is running... 2020/04/24 08:55:12.833 [I] [asm_amd64.s:1373] http server Running on http://:8080 |
说明应用运行成功了,访问地址为http://ip:8080,返回界面如下:

到此,新建的应用已经成功运行了。