This is a creation in
Article, where the information may have evolved or changed.
Today try to compile a Beego library, and by the way to learn a go installation environment.
The next decompression package is installed in the D: Directory go directory, set the
Goroot=d:\go
Goarch=386
Gobin=%goroot%\bin
Create a catalog project under D:\go, and then create a project Hellogo.
Hellogo The following directory structure is:
Hellogo
----SRC
------Hellogo.go (test for Beego)
-----pkg (optional)
----Bin (said this is optional, but I do not create when the build will fail)
-----Make.bat (used to compile the src file)
Since Hellogo.go is a test for Beego, the contents are as follows:
Hellogopackage Mainimport ( "Github.com/astaxie/beego") type Maincontroller struct { beego. Controller}func (This *maincontroller) Get () {this . Ctx.writestring ("Hello World, this is a Web program")}func Main () { beego. Registercontroller ("/", &maincontroller{}) //beego. Httpport = 8080//default Beego. Run ()}
Go build with fewer hints
Github.com/astaxie/beego
Package, then you need to use go get-v
Github.com/astaxie/beego
Download the package first, if using the default Gopath, the package will scare the go directory of SRC, and installed in the PKG, this will certainly pollute the system.
On the internet to collect the discovery using Make.bat to set up Gopath, set up to build their own src, and pkg under the.
However, the bin directory is not set up or not, either generated in the Go.exe directory, the following generated in the Hellogo.go directory.
Will not be generated to the./bin directory, finally only manually created/bin directory, with Go build-o%gobin%/hellogo.exe hellogo.go specified
The entire Make.bat content is as follows:
@echo Offsetlocalif exist make.bat goto Okecho Make.bat must be run from its Foldergoto end:okset oldgopath=%gopath%set G Opath=%~dp0set gobin=%gopath%\bingofmt-tabs=false-tabwidth=4-w srcgo get-v Github.com/astaxie/sessiongo get-v GitHub . Com/russross/blackfridaygo get-v Github.com/astaxie/beegogo build./src/beegogo Install beegormdir/s/q%GOBIN%mkdir% Gobin%go build-o%gobin%/hellogo.exe./src/hellogo.go:endecho finishepause
This method does not know right, but at least compile no problem, the program can also run normally.
Create a Web program a few lines of code is done, no longer to the previous learning ASP, ASP, like to deploy the environment.
is one of the main reasons that inspired me to learn the go language.
All right.