20130103Windows to compile the go program

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.