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

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!
主站蜘蛛池模板: 常德市| 峡江县| 七台河市| 峨眉山市| 肃宁县| 焉耆| 嘉峪关市| 高要市| 赤峰市| 海口市| 桓仁| 南安市| 浠水县| 阳朔县| 和政县| 洛阳市| 遵义市| 海城市| 泰州市| 新乐市| 清涧县| 农安县| 晋江市| 焉耆| 大渡口区| 绥宁县| 建平县| 太仆寺旗| 师宗县| 都昌县| 鹤岗市| 南木林县| 公主岭市| 河南省| 渝北区| 高雄县| 翁源县| 闵行区| 封丘县| 潮安县| 贵州省|