錯(cuò)誤集合
1. 安裝 beego
問題:
? go go get github.com/astaxie/beego
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
解決:
上面的情況是go的環(huán)境設(shè)置問題,執(zhí)行
go env -w GO111MODULE=auto
后執(zhí)行
go get github.com/astaxie/beego
改變環(huán)境問題后續(xù)還是會(huì)有問題
../../pkg/mod/golang.org/x/sys@v0.0.0-20191005200804-aed5e4c7ecf9/unix/zsyscall_darwin_amd64.go:90:3: //go:linkname must refer to declared function or variable
../../pkg/mod/golang.org/x/sys@v0.0.0-20191005200804-aed5e4c7ecf9/unix/zsyscall_darwin_amd64.go:105:3: //go:linkname must refer to declared function or variable
../../pkg/mod/golang.org/x/sys@v0.0.0-20191005200804-aed5e4c7ecf9/unix/zsyscall_darwin_amd64.go:121:3: //go:linkname must refer to declared function or variable
../../pkg/mod/golang.org/x/sys@v0.0.0-20191005200804-aed5e4c7ecf9/unix/zsyscall_darwin_amd64.go:121:3: too many errors
后續(xù)使用 mod 管理
創(chuàng)建新項(xiàng)目
cd 新項(xiàng)目
mod init
go get github.com/beego/bee/v2
export PATH=$PATH:<your_main_gopath>/bin
不知道哪一步出問題善茎,還是沒有生成 bee 可執(zhí)行文件。手動(dòng)編譯項(xiàng)目移動(dòng)到 go 文件下 bin
cd github.com/beego/bee
//直接編譯源碼
go build -o bee
//移動(dòng) bee 文件到 gopath /bin
2. beego路由 404
成功運(yùn)行項(xiàng)目,調(diào)用接口報(bào) 404
//重新執(zhí)行生成路由
bee generate routers