Go language Tour, support online coding exercises official introductory tutorial

Go language has high performance and is very suitable for back-end network and distributed programming, so it is favored by major Internet companies.

So how do you learn Go?

In fact, the official has prepared an online Go language tutorial for us — Go Language Tour (GoTour), support online coding exercises, it is essential for entry!

Let’s start from scratch and install Go and GoTour to help everyone have fun learning Go!

Install the Go

Go Chinese is a great place to learn Go, install Go, read tutorials, read technical documentation, find projects, ask for help, etc.

Go to the Go download page (studygolang.com/dl), depending on your operating system…

Windows and MacOS automatically configure environment variables and GOPATH. If the OS is Linux, manually configure environment variables.

More installation problems can read the installation instructions (docs.studygolang.com/doc/install… Rookie tutorial (www.runoob.com/go/go-envir…

After the installation is complete, enter the following command to check whether the installation is successful:

go version
Copy the code

If similar information is displayed, the installation is successful:

Run the following command to view the environment information about the installed Go:

go env
Copy the code

See the output below, where GOPATH represents the Go working directory where the code and projects we will be developing will reside. GOROOT represents the Go installation directory and has many class libraries.

Install Gotour

Gotour (Go Language Tour) is the official recommended basic course of Go language, learn at the same time, suitable for beginners.

Do not recommend the use of online gotour (tour.studygolang.com/welcome/1),…

So let’s install it and run it locally.

1. Download source code

Gotour first download the source code, need to go to the website to install hg (mercurial.selenic.com/wiki/Downlo…

Installed hg, clone code to $GOPATH/src/bitbucket.org/mikespook/ directory (the directory does not exist then manually create) :

# enter directory
cd $GOPATH/src/bitbucket.org/mikespook
# Download the gotour source code
hg clone https://bitbucket.org/mikespook/go-tour-zh
Copy the code

Note that $GOPATH is the directory corresponding to GOPATH in go env (/Users/yupili/go)

Gotour relies on many libraries, which need to be downloaded before compiling. Due to network problems (download source: golang.org), the go Get command may not be downloaded successfully. Therefore, we need to manually download the corresponding dependencies, mainly golang.org/x/tools and golang.org/x/net.

Go to GitHub and run the following command to download and place them in $GOPATH/src/golang.org/x:

# enter directory
cd $GOPATH/src/golang.org/x
Download tools and NET packages
git clone https://github.com/golang/net.git
git clone https://github.com/golang/tools.git
Copy the code

If you do not have Git installed, download and decompress the package to $GOPATH/src/golang.org/x:

2. Compile and install

Go to the downloaded gotour directory and compile and install the go source file:

Go to the gotour source directory
cd $GOPATH/src/bitbucket.org/mikespook/go-tour-zh/gotour
# build install
go install
Copy the code

If there is no output, congratulations!

3. Start the service

Finally, if you goto the $GOPATH/bin directory, you can see the generated gotour executable binary. Execute it:

Go to the bin directory
cd $GOPATH/bin
# to perform
gotour
Copy the code

The gotour service has been started on port 3999 of the machine:

OK, enjoy it and start the fun journey of learning the go language

Project address: www.code-nav.cn/rd/?rid=21d…