| |
|
35 |
%%
|
| |
|
36 |
|
| |
|
37 |
%%
|
| |
|
38 |
|
| |
|
39 |
$ cat helloworld.go
|
| |
|
40 |
package main
|
| |
|
41 |
import "fmt"
|
| |
|
42 |
// This is a demonstrative comment!
|
| |
|
43 |
func main() {
|
| |
|
44 |
fmt.Println("Hello World!")
|
| |
|
45 |
}
|
| |
|
46 |
%%
|
| |
|
47 |
|
| |
|
48 |
%%
|
| |
|
49 |
$ gofmt helloworld.go
|
| |
|
50 |
package main
|
| |
|
51 |
|
| |
|
52 |
import "fmt"
|
| |
|
53 |
|
| |
|
54 |
// This is a demonstrative comment!
|
| |
|
55 |
func main() {
|
| |
|
56 |
fmt.Println("Hello World!")
|
| |
|
57 |
}
|
| |
|
58 |
|
| |
|
59 |
%%
|
| |
|
60 |
|
| |
|
61 |
%%
|
| |
|
62 |
|
| |
|
63 |
$ godoc fmt | head
|
| |
|
64 |
use 'godoc cmd/fmt' for documentation on the fmt command
|
| |
|
65 |
|
| |
|
66 |
PACKAGE DOCUMENTATION
|
| |
|
67 |
|
| |
|
68 |
package fmt
|
| |
|
69 |
import "fmt"
|
| |
|
70 |
|
| |
|
71 |
%%
|
| |
|
72 |
|
| |
|
73 |
%%
|
| |
|
74 |
## The Go Programming Language - documentation in web server !
|
| |
|
75 |
|
| |
|
76 |
$ godoc -http=:8181
|
| |
|
77 |
%%
|
| |
|
78 |
|
| |
|
79 |
%%
|
| |
|
80 |
|
| |
|
81 |
## Go uses static linking by default
|
| |
|
82 |
$ go build helloworld.go
|
| |
|
83 |
|
| |
|
84 |
$ ls -l
|
| |
|
85 |
total 752
|
| |
|
86 |
-rwxr-x--- 1 ebal ebal 1855827 Oct 14 23:07 helloworld
|
| |
|
87 |
-rw-r----- 1 ebal ebal 109 Oct 14 23:05 helloworld.go
|
| |
|
88 |
|
| |
|
89 |
$ ./helloworld
|
| |
|
90 |
Hello World!
|
| |
|
91 |
|
| |
|
92 |
$ file helloworld
|
| |
|
93 |
helloworld: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
|
| |
|
94 |
|
| |
|
95 |
$ ldd helloworld
|
| |
|
96 |
not a dynamic executable
|
| |
|
97 |
|
| |
|
98 |
$ strip helloworld
|
| |
|
99 |
|
| |
|
100 |
$ ldd helloworld
|
| |
|
101 |
not a dynamic executable
|
| |
|
102 |
|
| |
|
103 |
$ ls -l helloworld
|
| |
|
104 |
-rwxr-x--- 1 ebal ebal 1226248 Oct 14 23:14 helloworld
|
| |
|
113 |
|
| |
|
114 |
%%
|
| |
|
115 |
|
| |
|
116 |
## Variables
|
| |
|
117 |
|
| |
|
118 |
GOROOT
|
| |
|
119 |
GOHOME
|
| |
|
120 |
GOBIN
|
| |
|
121 |
GOPATH
|
| |
|
122 |
|
| |
|
123 |
%%
|
| |
|
124 |
|
| |
|
125 |
%%
|
| |
|
126 |
|
| |
|
127 |
$ go help environment | head -5
|
| |
|
128 |
|
| |
|
129 |
The go command, and the tools it invokes, examine a few different
|
| |
|
130 |
environment variables. For many of these, you can see the default
|
| |
|
131 |
value of on your system by running 'go env NAME', where NAME is the
|
| |
|
132 |
name of the variable.
|
| |
|
133 |
|
| |
|
134 |
%%
|
| |
|
135 |
|
| |
|
136 |
%%
|
| |
|
137 |
|
| |
|
138 |
$ gofmt test.go
|
| |
|
139 |
package main
|
| |
|
140 |
|
| |
|
141 |
import (
|
| |
|
142 |
"fmt"
|
| |
|
143 |
"os"
|
| |
|
144 |
)
|
| |
|
145 |
|
| |
|
146 |
func main() {
|
| |
|
147 |
arguments := os.Args
|
| |
|
148 |
for i := 0; i < len(arguments); i++ {
|
| |
|
149 |
fmt.Println(arguments[i])
|
| |
|
150 |
}
|
| |
|
151 |
}
|
| |
|
152 |
|
| |
|
153 |
|
| |
|
154 |
$ go run test.go 1 2
|
| |
|
155 |
TMPDIR/go-build729121647/command-line-arguments/_obj/exe/test
|
| |
|
156 |
1
|
| |
|
157 |
2
|
| |
|
158 |
|
| |
|
159 |
%%
|
| |
|
160 |
|