You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/eBook/01.3.md
+22-22Lines changed: 22 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Go commands
4
4
5
-
The Go language comes with a complete set of command operation tools, you can execute the command line `go` to see them:
5
+
The Go language comes with a complete set of command operation tools. You can execute the command line `go` to see them:
6
6
7
7

8
8
@@ -14,23 +14,23 @@ These are all useful for us. Let's see how to use some of them.
14
14
15
15
This command is for compiling tests. It will compile dependence packages if it's necessary.
16
16
17
-
- If the package is not the `main` package such as `mymath` in section 1.2, nothing will be generated after you executed`go build`. If you need package file `.a` in `$GOPATH/pkg`, use `go install` instead.
17
+
- If the package is not the `main` package such as `mymath` in section 1.2, nothing will be generated after you execute`go build`. If you need package file `.a` in `$GOPATH/pkg`, use `go install` instead.
18
18
- If the package is the `main` package, it will generate an executable file in the same folder. If you want the file to be generated in `$GOPATH/bin`, use `go install` or `go build -o ${PATH_HERE}/a.exe.`
19
-
- If there are many files in the folder, but you just want to compile one of them, you should append file name after `go build`. For example, `go build a.go`. `go build` will compile all the files in the folder.
20
-
- You can also assign the name of file that will be generated. For instance, we have`mathapp` in section 1.2, use`go build -o astaxie.exe` will generate `astaxie.exe` instead of `mathapp.exe`. The default name is your folder name(non-main package) or the first source file name(main package).
19
+
- If there are many files in the folder, but you just want to compile one of them, you should append the file name after `go build`. For example, `go build a.go`. `go build` will compile all the files in the folder.
20
+
- You can also assign the name of the file that will be generated. For instance, in the`mathapp`project (in section 1.2), using`go build -o astaxie.exe` will generate `astaxie.exe` instead of `mathapp.exe`. The default name is your folder name(non-main package) or the first source file name(main package).
21
21
22
-
(According to [The Go Programming Language Specification](https://golang.org/ref/spec), package name should be the name after the word `package` in the first line of your source files, it doesn't have to be the same as folder's, and the executable file name will be your folder name as default.])
22
+
(According to [The Go Programming Language Specification](https://golang.org/ref/spec), package names should be the name after the word `package` in the first line of your source files. It doesn't have to be the same as the folder name, and the executable file name will be your folder name by default.])
23
23
24
-
-`go build` ignores files whose name starts with `_` or `.`.
25
-
- If you want to have different source files for every operating system, you can name files with system name as suffix. Suppose there are some source files for loading arrays, they could be named as follows.
24
+
-`go build` ignores files whose names start with `_` or `.`.
25
+
- If you want to have different source files for every operating system, you can name files with the system name as a suffix. Suppose there are some source files for loading arrays. They could be named as follows:
`go build` chooses the one that associated with your operating system. For example, it only compiles array_linux.go in Linux systems, and ignores all the others.
29
+
`go build` chooses the one that's associated with your operating system. For example, it only compiles array_linux.go in Linux systems, and ignores all the others.
30
30
31
31
## go clean
32
32
33
-
This command is for cleaning files that are generated by compilers, including the following files.
33
+
This command is for cleaning files that are generated by compilers, including the following files:
34
34
35
35
_obj/ // old directory of object, left by Makefiles
36
36
_test/ // old directory of test, left by Makefiles
@@ -43,24 +43,24 @@ This command is for cleaning files that are generated by compilers, including th
43
43
DIR.test(.exe) // generated by go test -c
44
44
MAINFILE(.exe) // generated by go build MAINFILE.go
45
45
46
-
I usually use this command to clean my files before I upload my project to the Github. These are useful for local tests, but useless for version control.
46
+
I usually use this command to clean up my files before I upload my project to Github. These are useful for local tests, but useless for version control.
47
47
48
48
## go fmt
49
49
50
-
The people who are working with C/C++ should know that people are always arguing about code style between K&R-style and ANSI-style, which one is better. However in Go, there is only one code style which is enforced. For example, you must put a left brace in the end of the line, and can't put it in a single line, otherwise you will get compile errors! Fortunately, you don't have to remember these rules. `go fmt` does this job for you. Just execute the command `go fmt <File name>.go` in terminal. I don't use this command very much because IDEs usually execute this command automatically when you save source files. I will talk about IDEs more in next section.
50
+
The people who are working with C/C++ should know that people are always arguing about which code style is better: K&R-style or ANSI-style. However in Go, there is only one code style which is enforced. For example, left braces must only be inserted at the end of lines, and they cannot be on their own lines, otherwise you will get compile errors! Fortunately, you don't have to remember these rules. `go fmt` does this job for you. Just execute the command `go fmt <File name>.go` in terminal. I don't use this command very much because IDEs usually execute this command automatically when you save source files. I will talk about IDEs more in the next section.
51
51
52
-
We usually use `gofmt -w` instead of `go fmt`, the latter will not rewrite your source files after formatted code. `gofmt -w src` formats the whole project.
52
+
We usually use `gofmt -w` instead of `go fmt`. The latter will not rewrite your source files after formatting code. `gofmt -w src` formats the whole project.
53
53
54
54
## go get
55
55
56
-
This command is for getting remote packages. It supports BitBucket, Github, Google Code and Launchpad so far. There are actually two things that happen after we execute this command. The first thing is to download the source code, then execute`go install`. Before you use this command, make sure you have installed all the related tools.
56
+
This command is for getting remote packages. So far, it supports BitBucket, Github, Google Code and Launchpad. There are actually two things that happen after we execute this command. The first thing is that Go downloads the source code, then executes`go install`. Before you use this command, make sure you have installed all of the related tools.
57
57
58
58
BitBucket (Mercurial Git)
59
59
Github (git)
60
60
Google Code (Git, Mercurial, Subversion)
61
61
Launchpad (Bazaar)
62
62
63
-
In order to use this command, you have to install these tools correctly. Don't forget to set `PATH`. By the way, it also supports customized domain names, use`go help remote` for more details.
63
+
In order to use this command, you have to install these tools correctly. Don't forget to set `$PATH`. By the way, it also supports customized domain names. Use`go help remote` for more details about this.
64
64
65
65
## go install
66
66
@@ -75,27 +75,27 @@ This command loads all files whose name include `*_test.go` and generates test f
75
75
ok compress/gzip 0.033s
76
76
...
77
77
78
-
It tests all your test files by default, use command `go help testflag` for more details.
78
+
It tests all your test files by default. Use command `go help testflag` for more details.
79
79
80
80
## go doc
81
81
82
-
Many people said that we don't need any third-party documentation for programming in Go (actually I've made a [CHM](https://github.com/astaxie/godoc) already), Go has a powerful tool to manage documentation by itself.
82
+
Many people say that we don't need any third-party documentation for programming in Go (actually I've made a [CHM](https://github.com/astaxie/godoc) already). Go has a powerful tool to manage documentation natively.
83
83
84
-
So how do we look up package information in documentation? If you want to get more details about the package `builtin`, use command`go doc builtin`, and use command`go doc net/http`for package `http`. If you want to see more details about specific functions, use command`godoc fmt Printf`, and `godoc -src fmt Printf` to view source code.
84
+
So how do we look up package information in documentation? For instance, if you want to get more details about the `builtin` package, use the`go doc builtin` command. Similarly, use the`go doc net/http`command to look up the `http` package documentation. If you want to see more details about specific functions, use the`godoc fmt Printf` and `godoc -src fmt Printf`commands to view the source code.
85
85
86
-
Execute command`godoc -http=:8080`, then open `127.0.0.1:8080` in your browsers, you should see a localized golang.org. It can not only show the standard packages' information, but also packages in your `$GOPATH/pkg`. It's great for people who are suffering from the Great Firewall of China.
86
+
Execute the`godoc -http=:8080` command, then open `127.0.0.1:8080` in your browser. You should see a localized golang.org. It can not only show the standard packages' information, but also packages in your `$GOPATH/pkg`. It's great for people who are suffering from the Great Firewall of China.
87
87
88
88
## Other commands
89
89
90
-
Go provides more commands then I just talked about.
90
+
Go provides more commands then those we've just talked about.
91
91
92
-
go fix // upgrade code from old version before go1 to new version after go1
93
-
go version // get information about Go version
92
+
go fix // upgrade code from an old version before go1 to a new version after go1
93
+
go version // get information about your version of Go
94
94
go env // view environment variables about Go
95
95
go list // list all installed packages
96
96
go run // compile temporary files and run the application
97
97
98
-
There are also more details about commands that I talked about, you can use `go help <command>` to get more information.
98
+
There are also more details about the commands that I've talked about. You can use `go help <command>` to look them up.
0 commit comments