Go is an open-source programming language that makes it easy to build software that is simple, reliable, and efficient.
Go was developed from the end of 2007 by Robert Griesemer, Rob Pike, Ken Thompson, and later joined Ian Lance Taylor, Russ Cox, and eventually open source in November 2009, A stable version of Go 1 was released earlier in 2012. Now the go development is completely open and has an active community.
The main features of the Go language:
- Automatic garbage collection
- Richer built-in types
- function multiple return value
- Error handling
- Anonymous functions and closures
- Types and Interfaces
- Concurrent programming
- Reflection
- Language interactivity
- Easy to deploy
Tell me why I studied go:
1. Superior performance: This is a well-known feature, born with high concurrency.
2. Ease of deployment: At first I just wanted to try something fresh, and then I wrote a little bit of code, and then I found that the compilation was very simple, and the deployment was a binary package (Linux) or EXE file (Windows), which was too convenient for the Ops people.
3. Recently learning Kuberneters, its implementation is also the go language, so I made a decision to learn go.
As a Python programmer, I am certainly familiar with Python, and it is well known that because the Gil problem caused the slow speed, of course, go to compensate for this shortcoming, because the beginner go does not understand, only from the words of others to understand the go and Python comparison:
https://studygolang.com/articles/3102
Http://developer.51cto.com/art/201710/555200.htm
Third, the development environment to build |
1. Download the package:
The installation package is: https://golang.org/dl/.
If you can't open it, you can use this address: https://golang.google.cn/dl/
Package name for each system:
Operating System |
Package Name |
Windows |
Go1.10.windows-amd64.msi |
Linux |
Go1.10.linux-amd64.tar.gz |
Mac |
Go1.10.darwin-amd64-osx10.8.pkg |
Freebsd |
Go1.10.freebsd-amd64.tar.gz |
2. Installation
Windows
Run the downloaded package and click on the next step, after the installation is complete, open cmd input go version If the correct version is returned to indicate the installation was successful.
Just installing the MSI is not enough, and there are a few things to configure:GOPATH
Go from version 1.1 to 1.7 this variable must be set and cannot be the same as the Go installation directory.
This directory is used to store the go source, go executable files, and the corresponding compiled package files.
So there are three subdirectories under this directory: src, bin, pkg
Starting with Go 1.8, the GOPATH environment variable now has a default value if it is not set. It defaults to on Unix $HOME/go
and defaults to on Windows %USERPROFILE%/go
.
If you are in a UNIX (mac/linux) environment, you need:
Export Gopath=/opt/src/go
Windows will need to create a new environment variable name is called Gopath, of course, go MSI installation package after installation, the default setting of Gopath, we just need to right-click "This Computer"-"Properties"-"Advanced system Settings"-"Advanced"-"Environment variables" settings editing can be
Gopath allow multiple directories, when there are multiple directories, note the delimiter, multiple directories when Windows is a semicolon, Linux system is a colon, when there are multiple Gopath, the default is to put the contents of go get in the first directory.
The above $GOPATH directory Convention has three subdirectories:
- SRC store source code (e.g.,. Go. C. h, etc.)
- The files generated by the PKG after compilation (for example:. a)
- The executable file generated by the bin after compilation (for convenience, you can add this directory to the
$PATH
variable, if there is more than one gopath, then use ${GOPATH//://bin:}/bin
the addition of all bin directory)
Unix/linux/mac OS X, and FreeBSD installation
The following describes the use of the source installation method under Unix/linux/mac OS X, and FreeBSD systems:
1, download the source package: go1.4.linux-amd64.tar.gz.
2. Extract the downloaded source package to the/usr/local directory.
tar -c/usr/local-xzf go1. 103. Linux-amd64. tar. gz
3. Add the/usr/local/go/bin directory to the PATH environment variable:
Export path= $PATH:/usr/local/go/bin
Ps:max If you install brew, you can also install it through brew
InstallInstall Golang
Create a new file Src/hello/hello.go under your Gopath, as follows:
" FMT " Func Main () { fmt. Println ("Hello, world! " )}
Cut into cmd use go run to run the file
You can also compile executable files to execute:
CMD down into the directory where the files are located, my directory is C:\Users\17647\Desktop\go_work\src\hello, run go bulid:
At this point you will find the directory is more than the. exe file to run directly on it
Go language Trip-Introduction and environment construction