简介
https://github.com/beego/beego
http://beego.gocn.vip/beego/zh/developing/
https://github.com/beego/beego-example
https://github.com/topics/beego
升级 beego:
| go get github.com/beego/beego/v2@latest
|
| $ go version
go version go1.18 darwin/amd64
$ where go
/usr/local/go/bin/go
|
设置 $GOPATH
:
在 ~/.zshrc
中设置
| export GOPATH="/Users/nocilantro/go"
export GOPROXY=https://goproxy.cn
export PATH="$GOPATH/bin:$PATH"
export GOMODCACHE="$HOME/go/pkg/mod"
export GOBIN="$GOPATH/bin"
|
然后 source ~/.zshrc
使其生效
| $ echo $GOPATH
/usr/local/go/bin/go
$ echo $GOPROXY
https://goproxy.cn
$ go env
GO111MODULE="on"
GOPATH="/usr/local/go/bin/go"
GOPROXY="https://goproxy.cn"
|
试用
| mkdir hello
cd hello
go mod init example.com/hello
go get github.com/beego/beego/v2@latest
|
踩坑(
| $ go get -u github.com/gin-gonic/gin
go: could not create module cache: stat /usr/local/go/bin/go/pkg/mod: not a directory
|
根据 go-zero 文档设置,但是我搞错了
按照下面的命令把 GOMODCACHE 设置成了 GOMODCACHE="/usr/local/go/bin/go/pkg/mod"
| go env -w GOMODCACHE=$GOPATH/pkg/mod
|
实际如果 GOMODCACHE 不为空或者 /dev/null
的话,不应该修改
所以修改回 export GOMODCACHE="$HOME/go/pkg/mod"
下载 bee 命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 | $ go install github.com/beego/bee/v2@master
$ bee version
2023/02/02 22:07:10.240 [D] init global config instance failed. If you do not use this, just ignore it. open conf/app.conf: no such file or directory
2023/02/02 22:07:10 INFO ▶ 0001 Getting bee latest version...
2023/02/02 22:07:11 INFO ▶ 0002 Your bee are up to date
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.4
├── GoVersion : go1.18
├── GOOS : darwin
├── GOARCH : amd64
├── NumCPU : 4
├── GOPATH : /Users/nocilantro/go
├── GOROOT : /usr/local/go
├── Compiler : gc
└── Date : Thursday, 2 Feb 2023
|
| ➜ beego git:(develop) pwd
/Users/nocilantro/go/src/github.com/astaxie/beego
|
出现错误:
| go: github.com/Knetic/govaluate@v3.0.0+incompatible: Get https://proxy.golang.org/github.com/%21knetic/govaluate/@v/v3.0.0+incompatible.mod: dial tcp 216.58.200.49:443: i/o timeout
|
解决方法:
我们可以通过GOPROXY来控制代理, 设置GOPROXY代理:
| go env -w GOPROXY=https://goproxy.cn,direct
|
| ➜ bee git:(develop) pwd
/Users/nocilantro/go/src/github.com/beego/bee
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | ➜ Desktop echo 'export PATH="$GOPATH/bin:$PATH"' >> ~/.zshrc
➜ Desktop exec $SHELL
➜ Desktop echo $SHELL
/bin/zsh
➜ Desktop bee version
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
├── Beego : 1.12.0
├── GoVersion : go1.13.4
├── GOOS : darwin
├── GOARCH : amd64
├── NumCPU : 4
├── GOPATH : /Users/nocilantro/go
├── GOROOT : /usr/local/g o
├── Compiler : gc
└── Date : Sunday, 2 Feb 2020
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | ➜ brew search mysql
==> Formulae
automysqlbackup mysql-connector-c++@1.1
mysql ✔ mysql-sandbox
mysql++ mysql-search-replace
mysql-client mysql@5.6
mysql-client@5.7 mysql@5.7
mysql-connector-c++ mysqltuner
==> Casks
mysql-connector-python mysqlworkbench
mysql-shell navicat-for-mysql
mysql-utilities sqlpro-for-mysql
➜ brew search mysql@5.7
==> Formulae
mysql@5.7
|
| ➜ src bee new hellobeego
➜ src ls
github.com hellobeego
➜ src cd hellobeego
➜ hellobeego ls
conf main.go routers tests
controllers models static views
➜ hellobeego bee run
|
http://127.0.0.1:8080/
bee 2.0.4 试用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | $ bee new hello
2023/02/02 22:27:50.451 [D] init global config instance failed. If you do not use this, just ignore it. open conf/app.conf: no such file or directory
2023/02/02 22:27:50 INFO ▶ 0001 Generate new project support go modules.
2023/02/02 22:27:50 INFO ▶ 0002 Creating application...
create /Users/nocilantro/Desktop/hello/go.mod
create /Users/nocilantro/Desktop/hello/
create /Users/nocilantro/Desktop/hello/conf/
create /Users/nocilantro/Desktop/hello/controllers/
create /Users/nocilantro/Desktop/hello/models/
create /Users/nocilantro/Desktop/hello/routers/
create /Users/nocilantro/Desktop/hello/tests/
create /Users/nocilantro/Desktop/hello/static/
create /Users/nocilantro/Desktop/hello/static/js/
create /Users/nocilantro/Desktop/hello/static/css/
create /Users/nocilantro/Desktop/hello/static/img/
create /Users/nocilantro/Desktop/hello/views/
create /Users/nocilantro/Desktop/hello/conf/app.conf
create /Users/nocilantro/Desktop/hello/controllers/default.go
create /Users/nocilantro/Desktop/hello/views/index.tpl
create /Users/nocilantro/Desktop/hello/routers/router.go
create /Users/nocilantro/Desktop/hello/tests/default_test.go
create /Users/nocilantro/Desktop/hello/main.go
2023/02/02 22:27:50 SUCCESS ▶ 0003 New application successfully created!
|
而后我们执行go mod tidy命令,来生成go.sum文件。
| $ go mod tidy
go: downloading github.com/beego/beego/v2 v2.0.1
go: downloading github.com/prometheus/client_golang v1.7.0
go: downloading golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58
go: downloading github.com/elazarl/go-bindata-assetfs v1.0.0
go: downloading github.com/mitchellh/mapstructure v1.3.3
go: downloading golang.org/x/net v0.0.0-20201021035429-f5854403a974
go: downloading github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1
go: downloading gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f
go: downloading golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f
go: downloading github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e
|
然后运行 bee run
出错:
| go:linkname must refer to declared function or variable
|
fixed:
| go get -u golang.org/x/sys
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 | $ bee run
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v2.0.4
2023/02/02 22:33:07 WARN ▶ 0001 Running application outside of GOPATH
2023/02/02 22:33:07 INFO ▶ 0002 Using 'hello' as 'appname'
2023/02/02 22:33:07 INFO ▶ 0003 Initializing watcher...
golang.org/x/sys/unix
github.com/prometheus/procfs
github.com/prometheus/client_golang/prometheus
github.com/prometheus/client_golang/prometheus/promhttp
github.com/beego/beego/v2/server/web
hello/controllers
hello/routers
hello
2023/02/02 22:33:14 SUCCESS ▶ 0004 Built Successfully!
2023/02/02 22:33:14 INFO ▶ 0005 Restarting 'hello'...
2023/02/02 22:33:14 SUCCESS ▶ 0006 './hello' is running...
2023/02/02 22:33:15.144 [I] [parser.go:413] generate router from comments
2023/02/02 22:33:15.145 [I] [server.go:241] http server Running on http://:8080
|
http://127.0.0.1:8080/
| 2023/02/02 22:33:55.946 [D] [router.go:955] | 127.0.0.1| 200 | 27.346691ms| match| GET / r:/
2023/02/02 22:33:56.062 [D] [router.go:955] | 127.0.0.1| 200 | 2.01684ms| match| GET /static/js/reload.min.js
|
MVC