官术网_书友最值得收藏!

Getting ready for Go

You can easily find your version of Go using this command:

$ go version
go version go1.7.5 darwin/amd64  

The previous output is from a macOS machine hence the darwin string. A Linux machine would give the following kind of output:

$ go version
go version go1.3.3 linux/amd64

You will learn more about go tool, which you will use all the time, in the next chapters.

As I can imagine, you must be impatient to see some Go code; so here is the Go version of the famous Hello World program:

package main 
 
import "fmt" 
 
// This is a demonstrative comment! 
func main() { 
   fmt.Println("Hello World!") 
} 

If you are familiar with C or C++, you will find Go code pretty easy to understand. Each file that contains Go code begins with a package declaration followed by the needed import declarations. The package declaration shows the package that this file belongs to. Note that semicolons are not required for successfully terminating a Go statement unless you want to put two or more Go statements in the same line.

In Chapter 2, Writing Programs in Go, you will find out how to compile and execute Go code. For now, it is enough to remember that Go source files are stored using the .go file extension: your task is to choose a descriptive filename.

When searching for Go-related information, use Golang or golang as the keyword for the Go programming language because the word Go can be found almost everywhere in the English language and it will not help your search!
主站蜘蛛池模板: 刚察县| 永定县| 嘉义县| 博爱县| 福清市| 芮城县| 永平县| 云安县| 临湘市| 桐乡市| 山阴县| 疏勒县| 南漳县| 丹阳市| 师宗县| 英山县| 崇左市| 澜沧| 福鼎市| 安图县| 舟山市| 东乡县| 内黄县| 宁陕县| 文山县| 松潘县| 九寨沟县| 萨嘎县| 高清| 义乌市| 秭归县| 星座| 通州市| 阿鲁科尔沁旗| 张家界市| 鹤山市| 滦平县| 永寿县| 忻城县| 宁晋县| 葵青区|