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

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!
主站蜘蛛池模板: 龙川县| 新民市| 贵溪市| 洛宁县| 垣曲县| 德保县| 海盐县| 阳西县| 彰化县| 湘西| 公主岭市| 台东市| 喀喇沁旗| 聂荣县| 甘德县| 梓潼县| 玉屏| 黔南| 陇南市| 绩溪县| 政和县| 徐闻县| 宜州市| 昌乐县| 怀远县| 通河县| 廊坊市| 德令哈市| 吴旗县| 潼关县| 确山县| 通河县| 北川| 谷城县| 山东| 北海市| 嘉荫县| 金塔县| 蒙自县| 白山市| 黎平县|