go语言框架beego环境搭建
1.安装beego;
go get -u github.com/astaxie/beego
go get -u github.com/beego/bee
当出现如下错误的时候
C:\Users\Administrator>go get -u github.com/astaxie/beego C:\Users\Administrator>go get -u github.com/beego/bee # cd .; git clone -- https://gopkg.in/yaml.v2 D:\GoWork\src\gopkg.in\yaml.v2 Cloning into 'D:\GoWork\src\gopkg.in\yaml.v2'... fatal: unable to access 'https://gopkg.in/yaml.v2/': SSL certificate problem: certificate has expired package gopkg.in/yaml.v2: exit status 128 # cd .; git clone -- https://gopkg.in/yaml.v3 D:\GoWork\src\gopkg.in\yaml.v3 Cloning into 'D:\GoWork\src\gopkg.in\yaml.v3'... fatal: unable to access 'https://gopkg.in/yaml.v3/': SSL certificate problem: certificate has expired package gopkg.in/yaml.v3: exit status 128 cannot find package "github.com/hashicorp/hcl/hcl/printer" in any of: C:\Program Files\go\src\github.com\hashicorp\hcl\hcl\printer (from $GOROOT) D:\GoWork\src\github.com\hashicorp\hcl\hcl\printer (from $GOPATH) # cd .; git clone -- https://gopkg.in/ini.v1 D:\GoWork\src\gopkg.in\ini.v1 Cloning into 'D:\GoWork\src\gopkg.in\ini.v1'... fatal: unable to access 'https://gopkg.in/ini.v1/': SSL certificate problem: certificate has expired package gopkg.in/ini.v1: exit status 128
进行如下操作
go env -w GO111MODULE=on
C:\Users\Administrator>go get -u github.com/beego/beego/v2
C:\Users\Administrator>go get -u github.com/beego/bee/v2
2.下载完成后配置GOBIN的环境变量
在环境变量中配置GOBIN参数为bee的路径,例如:D:\GoWork\bin
然后在path后面追加%GOBIN%
保存验证GOBIN的环境变量是否生效
3.创建beego项目
D:\GoProject>bee new hello
D:\GoProject\hello>bee run hello
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.2
2022/06/07 15:19:36 WARN ? 0001 Running application outside of GOPATH
2022/06/07 15:19:36 INFO ? 0002 Using 'hello' as 'appname'
2022/06/07 15:19:36 INFO ? 0003 Initializing watcher...
main.go:5:2: missing go.sum entry for module providing package github.com/beego/beego/v2/server/web (imported by hello); to add:
go get hello
2022/06/07 15:19:36 ERROR ? 0004 Failed to build the application: main.go:5:2: missing go.sum entry for module providing package github.com/beego/beego/v2/server/web (imported by hello); to add:
go get hello
4.出现failed的原因是系统没有下载一些依赖包,需要执行
D:\GoProject\hello>go mod tidy
然后执行启动beego项目,就可以通过浏览器访问beego项目