ubuntu下beego环境搭建

ubuntu下beego环境搭建

  • beego环境搭建
    • 一、前提条件:
    • 二、beego搭建步骤
    • 三、安装并使用bee命令快速生成项目的基本结构

beego环境搭建

一、前提条件:

1、本次安装使用的操作系统:

test@test:~$ uname -a
Linux test 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
test@test:~$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"

2、本地go语言环境已搭建完毕,涉及到的环境变量(GOPATH、GOROOT)都已正确设置,检查方法:

test@test:~$ go version
go version go1.12.4 linux/amd64

二、beego搭建步骤

1、安装beego

go get github.com/astaxie/beego

2、编写第一个beego测试项目:

package main
import "github.com/astaxie/beego"
func main() {
    beego.Run()
}

3、编译并执行:
go build hello.go
./hello
4、打开浏览器输入:http://localhost:8080 ,我本地没有显示官方说的欢迎界面,但显示如下错误界面,也明显表明beego环境正确执行了,具体的原因后续再分析。
ubuntu下beego环境搭建_第1张图片

三、安装并使用bee命令快速生成项目的基本结构

1、安装bee命令
go get github.com/beego/bee
注意:bee命令默认安装在$GOPAT/bin下,如果没有配置好环境变量,执行bee命令会报如下错误:

test@test:~/work/project_go/src/github.com/astaxie/beego$ bee version

Command 'bee' not found, did you mean:

需要自行进行配置,本文不表。

验证bee安装成功的方法:

test@test:~/work/project_go/src/silent_harbor$ bee version
______
| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v1.10.0

├── Beego     : 1.12.0
├── GoVersion : go1.12.4
├── GOOS      : linux
├── GOARCH    : amd64
├── NumCPU    : 8
├── GOPATH    : /home/ding/work/project_go:/home/ding/work/jk/algo:/home/ding/work/project_go/goeg:/home/ding/work/project_go/Golang_Puzzlers-master
├── GOROOT    : /usr/local/go
├── Compiler  : gc
└── Date      : Sunday, 21 Jul 2019

2、使用命令创建web项目

bee new webtest
test@test:~/work/project_go/src$ bee new mywebtest
______
| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v1.10.0
2019/07/21 05:42:49 INFO     ▶ 0001 Creating application...
	create	 /home/ding/work/project_go/src/mywebtest/
	create	 /home/ding/work/project_go/src/mywebtest/conf/
	create	 /home/ding/work/project_go/src/mywebtest/controllers/
	create	 /home/ding/work/project_go/src/mywebtest/models/
	create	 /home/ding/work/project_go/src/mywebtest/routers/
	create	 /home/ding/work/project_go/src/mywebtest/tests/
	create	 /home/ding/work/project_go/src/mywebtest/static/
	create	 /home/ding/work/project_go/src/mywebtest/static/js/
	create	 /home/ding/work/project_go/src/mywebtest/static/css/
	create	 /home/ding/work/project_go/src/mywebtest/static/img/
	create	 /home/ding/work/project_go/src/mywebtest/views/
	create	 /home/ding/work/project_go/src/mywebtest/conf/app.conf
	create	 /home/ding/work/project_go/src/mywebtest/controllers/default.go
	create	 /home/ding/work/project_go/src/mywebtest/views/index.tpl
	create	 /home/ding/work/project_go/src/mywebtest/routers/router.go
	create	 /home/ding/work/project_go/src/mywebtest/tests/default_test.go
	create	 /home/ding/work/project_go/src/mywebtest/main.go
2019/07/21 05:42:49 SUCCESS  ▶ 0002 New application successfully created!

切换到mywebtest目录,通过bee命令运行项目
bee run
浏览器访问:http://localhost:8080 输出如下界面:
ubuntu下beego环境搭建_第2张图片
3、使用命令创建api项目
bee api apitest
这里没有做测试,主要先研究web功能

完结

你可能感兴趣的:(beego,go)