This is a creation in Article, where the information may have evolved or changed.
Recent projects need to be developed 抗并发的db proxy,API GATEWAY and so on, along with various problems in the process of virtualization. As an old programmer, the Go language learning is urgent.
First, the basic background
Go is a programming language developed by Google 静态强类型、编译型、并发型 , and 具有垃圾回收 features
For the features of the Go language, the online Daniel Summary, for the individual special value 语言交互和并发性 :
- 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
Second, installation
Suggested References:
Http://dmdgeeker.com/goBook/d ...
It is important to note that Gopath must be configured, configured to its own workspace:
# go path change by cuihuanexport GOPATH=/Users/cuixiaohuan/Desktop/workspace/goexport GOBIN=$GOPATH/binexport PATH=$PATH:$GOPATH
Workspace's Basic directory specification can be consulted: https://go-zh.org/doc/code.html
- The SRC directory contains the source files for go, which are organized into packages (each directory corresponds to a package).
- The PKG directory contains the package object,
- The bin directory contains executable commands.
Third, Hello World
Code
package mainimport "fmt"func main() { fmt.Println("Hello World")}
Language Description:
1:package is required, for standalone run executable files, must be package main
2:import represents the introduced package, or the library
3: Main function in the program
4: Execute function
Run:
cuixiaozhuai:main cuixiaohuan$ go build hello.gocuixiaozhuai:main cuixiaohuan$ ./helloHello World
Compile and run are very simple, and more convenient is the cross-platform compilation
# mac 下编译cuixiaozhuai:main cuixiaohuan$ env GOOS=linux GOARCH=amd64 GOARM=7 go build hello.go # linux 开发机运行[work@xx.com ~]$ ./helloHello World
"Reprint Please specify:" Go learning One "Hello World | "A very small and reliable"