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

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!
主站蜘蛛池模板: 韩城市| 龙州县| 邻水| 青阳县| 旅游| 达孜县| 左云县| 三台县| 阿拉善左旗| 图片| 龙川县| 德惠市| 金阳县| 榆林市| 尉氏县| 敦煌市| 浏阳市| 轮台县| 锦州市| 霍邱县| 佳木斯市| 定陶县| 马山县| 保山市| 宜丰县| 荣昌县| 蓝田县| 翁源县| 永泰县| 深州市| 德江县| 义乌市| 铜鼓县| 灵寿县| 府谷县| 丹江口市| 专栏| 黄梅县| 香河县| 沙河市| 晴隆县|