beego安装失败_beego安装失败解决方法

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

ec4c1f4fdafbce405138fc52d184abf1.png

解决方法

设置代理;首先更改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

a6d1f54c8b1733027b90f9737dfa22fd.png

第一个Beego项目

首先bee new beego_project 创建名为beego_project的项目

58b03d5c45c6ab9ad84689491b968508.png

在项目根目录下执行bee run或者go run main.go

eaa60210a15969772ede7bb1f4321f59.png

执行完后访问http://127.0.0.1:8080/; 看到下图说明我们构建项目成功了

e9b393a18574606e9a474f0ccbda98c6.png

beego的项目结构conf目录为项目的配置文件; controllers为项目的视图;

models为orm模型;routers为路由映射;static目录是存放静态文件;

tests是存放单元测试代码的目录;views是存放html文件的目录;main.go项目运行总入口

9565987e75bc921b1bc8e9c6ead216b5.png

接下来我们编写一个视图来小试牛刀一下;在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

0f811754d370906fdec0f7de498c87e0.png

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值