Beego安装失败
安装beego出现报错fatal: unable to access 'https://github.com/spf13/jwalterweatherman/': Failed to connect to github.com port 443: Timed out package github.com/spf13/jwalterweatherman: exit status 128
解决方法
设置代理;首先更改golang的配置网上有两种配置方法
go env -w GOPROXY=https://goproxy.io,directgo env -w GO111MODULE=on
再执行
go get -u github.com/beego/beego get -u github.com/astaxie/beego
安装成功了,测试一下 bee version
第一个Beego项目
首先bee new beego_project 创建名为beego_project的项目
在项目根目录下执行bee run或者go run main.go
执行完后访问http://127.0.0.1:8080/; 看到下图说明我们构建项目成功了
beego的项目结构conf目录为项目的配置文件; controllers为项目的视图;
models为orm模型;routers为路由映射;static目录是存放静态文件;
tests是存放单元测试代码的目录;views是存放html文件的目录;main.go项目运行总入口
接下来我们编写一个视图来小试牛刀一下;在controllers/default.go文件编写
type UserController struct { beego.Controller}func (u *UserController) Get(){ u.Data["username"] = "你大爷" u.Data["property"] = "快乐" u.TplName = "user.html"}
第二步关联路由映射 routers/router.go文件
beego.Router("/user", &controllers.UserController{})
第三步views目录下新建user.html
<html lang="en"><head> <meta charset="UTF-8"> <title>Titletitle>head><body> <h1>{{.username}}我很{{.property}}h1>body>html>
重新启动项目访问http://127.0.0.1:8080/user