Table of contents
Environment configuration:
First install and configure the golang environment
You can refer to my other article. Although it is a centos7 system, it is basically applicable to the way of installing golang on ubuntu22.04
In ubuntu, in order to facilitate installation and download dependent packages, I configured the following items in ~/.bashrc
# golang dev env
export GOROOT=$HOME/dev_env/go
export GOPATH=$HOME/work/go
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
export GO111MODULE=on
export GOPROXY="https://goproxy.cn,direct"
Create a directory to independently store beego source code and bee source code. Due to the shortcomings of GOPATH in package management, I only use the go mod mechanism to download dependent packages. However, using go mod also has the problem that go get dependent packages may not be downloaded successfully. and there will be
'go get' is no longer supported outside a module', I only use git to download the source code, and use the go.mod inside the source code to download the dependencies
mkdir -p $HOME/work/beego_dev && cd $HOME/work/beego_dev
Then download beego and bee
git clone https://github.com/beego/bee.git
git clone https://github.com/beego/beego.git
Then compile bee, a tool for building beego projects. Since there is already go.mod in the downloaded source code of bee, some build dependency packages will be automatically downloaded when go build
cd bee
go build
After go build, you will find that there will be an extra bee
After generating bee, put bee in the environment variable, here I put bee in GOBIN
After putting bee into the environment variable, the source code of beego and bee downloaded by git just now can actually be deleted, because the new api project created by bee can manage dependent packages through go mod tidy
cp bee $GOBIN
Result verification
Let's just change the working directory and execute bee version
Create an api project to test
bee api webserver
Summarize:
Since the go1.11 version, golang began to support the package management mechanism of go mod, and now most open source projects of golang also support go.mod in the project, which is very convenient for project configuration. Generally, the environment of golang is configured. Good GOPATH, download the source code of the project directly, set GO111MODULE="on", go build directly, just download the source code with git, and build the project with the internal go.mod