-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto commit by GitBook Editor
- Loading branch information
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
我们从经典的Hello Word程序开始,1978年《C语言编程》出版的时候也是这么干的。C应该说是对Go语言产生直接影响最大的语言之一,从Hello World这个例子我们就能看出一些端倪 | ||
|
||
![](/assets/helloworld.png) | ||
|
||
Go是一个编译语言。Go工具链会把源代码以及相关依赖包转换成为计算机底层原生机器语言的指令。这些工具链只通过一个命令来管理:go。go命令有一系列的子命令,对应各个工具集操作。最简单的子命令就是run,该命令可以编译一个或多个命名为.go的源代码文件,链接依赖库,然后运行编译结果(但是不会留下编译好的可执行文件)。我们在本书中用$符号表示命令提示符。 | ||
|
||
$ go run hellowolrd.go | ||
|
||
毫无悬念,屏幕上将会得到一下输出: | ||
|
||
Hello,世界 | ||
|
||
Go原生自带Unicode的处理,所以可以处理世界上各种语言的文本。 | ||
|
||
如果程序只实现性的运行一次无法满足需求,那么你应该会想要保存编译出的结果已被将来调用。那么这时就应该使用go build命令: | ||
|
||
$ go build helloworld.go | ||
|
||
然后一个名为helloworld的可执行的二进制文件就编译出来了,下次直接运行可执行文件即可,不用在进行重复的编译过程。 | ||
|
||
$ .\/helloworld | ||
|
||
Hello, 世界 | ||
|
||
为了方便使用,本书的代码都标注好了名字,你可以在gopl.io\/ch1\/helloworld下获得刚才的源码。 | ||
|
||
如果你运行go get gopl.io\/ch1\/helloworld, 该命令就会从网络上对应地址获取源码,存放到本地的相应目录中。在2.6节和10.7节中会有更详细的描述。 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Table of content | ||
# Summary | ||
|
||
* [Introduction](README.md) | ||
* [第一章 导论](chapter1.md) | ||
* [1.1 Hello,World](11-hello.md) | ||
|
||
* [First Chapter](chapter1.md) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.