GO语言学习笔记(一)Go语言的初步了解

Mr大表哥 · · 619 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

一·、Go语言的官方网站
https://golang.org/dl/
二、安装Go语言
Linux版本:

tar zxf go1.11.4.linux-amd64.tar.gz
mv go /usr/local/

三、设置GOPATH和GOROOT环境变量

vim /etc/profile

增加这三行:

export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
export GOPATH=$GOROOT/gocode

使其生效:source /etc/profile

四、验证

执行:go version

go version go1.11.4 linux/amd64

五、Go环境变量介绍

执行:go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/go/gocode/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""386、
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build119196690=/tmp/go-build -gno-record-gcc-switches"

GOROOT="/usr/local/go" //表示Go在服务器上安装位置
GOPATH="/usr/local/go/gocode/" //表示Go语言的工作目录
GOARCH="amd64" //表示机器的处理器架构,值可以是:386、amd64、arm
GOOS="linux" //表示当前机器的操作系统,值可以是:darwin、freebsd、linux、windows(其中darwin就是mac系统)
GOBIN="" //表示编译器和链接器的安装位置,默认位置是 $GOROOT/bin,一般情况下你可以将它的值设置为空,Go 将会使用前面提到的默认值

六、Go语言源码路径说明

[root@Go ~]# ls -l /usr/local/go
total 180
drwxr-xr-x  2 root root   258 Dec 15 07:36 api
-rw-r--r--  1 root root 55284 Dec 15 07:36 AUTHORS
drwxr-xr-x  2 root root    42 Dec 15 07:48 bin
-rw-r--r--  1 root root  1339 Dec 15 07:36 CONTRIBUTING.md
-rw-r--r--  1 root root 71070 Dec 15 07:36 CONTRIBUTORS
drwxr-xr-x  8 root root  4096 Dec 15 07:36 doc
-rw-r--r--  1 root root  5686 Dec 15 07:36 favicon.ico
drwxr-xr-x  2 root root     6 Jan 23 15:30 gocode
drwxr-xr-x  3 root root    18 Dec 15 07:36 lib
-rw-r--r--  1 root root  1479 Dec 15 07:36 LICENSE
drwxr-xr-x 15 root root   202 Dec 15 07:48 misc
-rw-r--r--  1 root root  1303 Dec 15 07:36 PATENTS
drwxr-xr-x  9 root root   199 Dec 15 07:48 pkg
-rw-r--r--  1 root root  1607 Dec 15 07:36 README.md
-rw-r--r--  1 root root    26 Dec 15 07:36 robots.txt
drwxr-xr-x 46 root root  4096 Dec 15 07:36 src
drwxr-xr-x 22 root root  8192 Dec 15 07:48 test
-rw-r--r--  1 root root     8 Dec 15 07:36 VERSION

1)bin目录

-rwxr-xr-x 1 root root 13057654 Dec 15 07:38 go
-rwxr-xr-x 1 root root 16006569 Dec 15 07:48 godoc
-rwxr-xr-x 1 root root  3373518 Dec 15 07:38 gofmt

包含可执行文件,如:编辑器、Go工具

2)doc目录

drwxr-xr-x 3 root root     85 Dec 15 07:36 articles
-rw-r--r-- 1 root root  33541 Dec 15 07:36 asm.html
-rw-r--r-- 1 root root   3006 Dec 15 07:36 cmd.html
-rw-r--r-- 1 root root  16933 Dec 15 07:36 code.html
drwxr-xr-x 2 root root    202 Dec 15 07:46 codewalk
-rw-r--r-- 1 root root   8701 Dec 15 07:36 conduct.html
-rw-r--r-- 1 root root   4586 Dec 15 07:36 contrib.html
-rw-r--r-- 1 root root  36834 Dec 15 07:36 contribute.html
-rw-r--r-- 1 root root  16577 Dec 15 07:36 debugging_with_gdb.html
drwxr-xr-x 2 root root     65 Dec 15 07:36 devel
-rw-r--r-- 1 root root  17573 Dec 15 07:36 diagnostics.html
-rw-r--r-- 1 root root   8865 Dec 15 07:36 docs.html
-rw-r--r-- 1 root root   1405 Dec 15 07:36 editors.html
-rw-r--r-- 1 root root 116452 Dec 15 07:36 effective_go.html
-rw-r--r-- 1 root root   4319 Dec 15 07:36 gccgo_contribute.html
-rw-r--r-- 1 root root  17052 Dec 15 07:36 gccgo_install.html
-rw-r--r-- 1 root root  59265 Dec 15 07:36 go1.10.html
-rw-r--r-- 1 root root  36305 Dec 15 07:36 go1.11.html
-rw-r--r-- 1 root root  40411 Dec 15 07:36 go1.1.html
-rw-r--r-- 1 root root  35000 Dec 15 07:36 go1.2.html
-rw-r--r-- 1 root root  23115 Dec 15 07:36 go1.3.html
-rw-r--r-- 1 root root  33535 Dec 15 07:36 go1.4.html
-rw-r--r-- 1 root root  47800 Dec 15 07:36 go1.5.html
-rw-r--r-- 1 root root  37592 Dec 15 07:36 go1.6.html
-rw-r--r-- 1 root root  43702 Dec 15 07:36 go1.7.html
-rw-r--r-- 1 root root  59014 Dec 15 07:36 go1.8.html
-rw-r--r-- 1 root root  37538 Dec 15 07:36 go1.9.html
-rw-r--r-- 1 root root   7216 Dec 15 07:36 go1compat.html
-rw-r--r-- 1 root root  71461 Dec 15 07:36 go1.html
-rw-r--r-- 1 root root  89479 Dec 15 07:36 go_faq.html
-rw-r--r-- 1 root root   8843 Dec 15 07:36 go-logo-black.png
-rw-r--r-- 1 root root   9360 Dec 15 07:36 go-logo-blue.png
-rw-r--r-- 1 root root  21469 Dec 15 07:36 go-logo-white.png
-rw-r--r-- 1 root root  13497 Dec 15 07:36 go_mem.html
drwxr-xr-x 3 root root   4096 Dec 15 07:36 gopher
-rw-r--r-- 1 root root 204825 Dec 15 07:36 go_spec.html
-rw-r--r-- 1 root root   3128 Dec 15 07:36 help.html
-rw-r--r-- 1 root root     34 Dec 15 07:36 ie.css
-rw-r--r-- 1 root root   9159 Dec 15 07:36 install.html
-rw-r--r-- 1 root root  19777 Dec 15 07:36 install-source.html
drwxr-xr-x 2 root root    131 Dec 15 07:36 play
drwxr-xr-x 2 root root   4096 Dec 15 07:36 progs
-rw-r--r-- 1 root root   4520 Dec 15 07:36 root.html
-rw-r--r-- 1 root root   8411 Dec 15 07:36 security.html
-rw-r--r-- 1 root root   2993 Dec 15 07:36 share.png
-rw-r--r-- 1 root root    360 Dec 15 07:36 tos.html

包含示例程序、代码工具、本地文档等

3)lib目录

[root@Go go]# ls -l lib/
drwxr-xr-x 2 root root 59 Jan 24 17:33 time
[root@Go go]# ls -l lib/time/
-rw-r--r-- 1 root root    378 Dec 15 07:36 README
-rwxr-xr-x 1 root root   1367 Dec 15 07:36 update.bash
-rw-r--r-- 1 root root 365101 Dec 15 07:36 zoneinfo.zip

包含文档模板

4)misc目录

drwxr-xr-x  2 root root   64 Dec 15 07:36 android
drwxr-xr-x  2 root root   15 Dec 15 07:36 arm
-rwxr-xr-x  1 root root  110 Dec 15 07:36 benchcmp
drwxr-xr-x 20 root root 4096 Dec 15 07:36 cgo
drwxr-xr-x  3 root root   24 Dec 15 07:36 chrome
-rw-r--r--  1 root root  159 Dec 15 07:36 editors
drwxr-xr-x  2 root root   24 Dec 15 07:36 git
drwxr-xr-x  2 root root   86 Dec 15 07:36 ios
drwxr-xr-x  2 root root   26 Dec 15 07:36 linkcheck
drwxr-xr-x  3 root root  150 Dec 15 07:36 nacl
drwxr-xr-x  2 root root   23 Dec 15 07:36 sortac
drwxr-xr-x  4 root root   35 Dec 15 07:36 swig
drwxr-xr-x  7 root root   79 Dec 15 07:48 tour
drwxr-xr-x  2 root root   53 Dec 15 07:36 trace
drwxr-xr-x  2 root root   71 Dec 15 07:36 wasm

包含与支持Go编辑器有关的配置文件以及cgo的示例

5)src目录

-rwxr-xr-x  1 root root   407 Dec 15 07:36 all.bash
-rw-r--r--  1 root root   726 Dec 15 07:36 all.bat
-rwxr-xr-x  1 root root   385 Dec 15 07:36 all.rc
-rwxr-xr-x  1 root root  2622 Dec 15 07:36 androidtest.bash
drwxr-xr-x  4 root root    28 Dec 15 07:36 archive
-rwxr-xr-x  1 root root  3738 Dec 15 07:36 bootstrap.bash
drwxr-xr-x  2 root root   123 Dec 15 07:36 bufio
-rwxr-xr-x  1 root root  1818 Dec 15 07:36 buildall.bash
drwxr-xr-x  2 root root    24 Dec 15 07:36 builtin
drwxr-xr-x  2 root root   234 Dec 15 07:36 bytes
-rwxr-xr-x  1 root root   521 Dec 15 07:36 clean.bash
-rw-r--r--  1 root root   565 Dec 15 07:36 clean.bat
-rwxr-xr-x  1 root root   380 Dec 15 07:36 clean.rc
drwxr-xr-x 24 root root   289 Dec 15 07:36 cmd
-rw-r--r--  1 root root  1519 Dec 15 07:36 cmp.bash
drwxr-xr-x  8 root root    83 Dec 15 07:36 compress
drwxr-xr-x  5 root root    42 Dec 15 07:36 container
drwxr-xr-x  2 root root   131 Dec 15 07:36 context
drwxr-xr-x 20 root root   275 Dec 15 07:36 crypto
drwxr-xr-x  3 root root    17 Dec 15 07:36 database
drwxr-xr-x  8 root root    82 Dec 15 07:36 debug
drwxr-xr-x 13 root root   161 Dec 15 07:36 encoding
drwxr-xr-x  2 root root    68 Dec 15 07:36 errors
drwxr-xr-x  2 root root    45 Dec 15 07:36 expvar
drwxr-xr-x  2 root root   115 Dec 15 07:36 flag
drwxr-xr-x  2 root root   176 Dec 15 07:36 fmt
drwxr-xr-x 14 root root   173 Dec 15 07:36 go
drwxr-xr-x  6 root root   201 Dec 15 07:36 hash
drwxr-xr-x  3 root root   151 Dec 15 07:36 html
drwxr-xr-x  9 root root  4096 Dec 15 07:36 image
drwxr-xr-x  3 root root    33 Dec 15 07:36 index
drwxr-xr-x 12 root root   194 Dec 15 07:36 internal
drwxr-xr-x  3 root root   146 Dec 15 07:36 io
-rwxr-xr-x  1 root root  2116 Dec 15 07:36 iostest.bash
drwxr-xr-x  3 root root    76 Dec 15 07:36 log
-rwxr-xr-x  1 root root  6339 Dec 15 07:36 make.bash
-rw-r--r--  1 root root  3946 Dec 15 07:36 make.bat
-rw-r--r--  1 root root   553 Dec 15 07:36 Make.dist
-rwxr-xr-x  1 root root  3136 Dec 15 07:36 make.rc
drwxr-xr-x  6 root root  8192 Dec 15 07:36 math
drwxr-xr-x  5 root root  4096 Dec 15 07:36 mime
-rwxr-xr-x  1 root root  1255 Dec 15 07:36 naclmake.bash
-rwxr-xr-x  1 root root  1216 Dec 15 07:36 nacltest.bash
drwxr-xr-x 10 root root  8192 Dec 15 07:36 net
drwxr-xr-x  5 root root  4096 Dec 15 07:39 os
drwxr-xr-x  3 root root   117 Dec 15 07:36 path
drwxr-xr-x  2 root root    70 Dec 15 07:36 plugin
-rwxr-xr-x  1 root root   976 Dec 15 07:36 race.bash
-rw-r--r--  1 root root  1037 Dec 15 07:36 race.bat
drwxr-xr-x  2 root root  4096 Dec 15 07:36 reflect
drwxr-xr-x  4 root root   232 Dec 15 07:36 regexp
-rwxr-xr-x  1 root root  1681 Dec 15 07:36 run.bash
-rw-r--r--  1 root root  1147 Dec 15 07:36 run.bat
-rwxr-xr-x  1 root root   418 Dec 15 07:36 run.rc
drwxr-xr-x 10 root root 16384 Dec 15 07:36 runtime
drwxr-xr-x  2 root root   334 Dec 15 07:36 sort
drwxr-xr-x  3 root root  4096 Dec 15 07:36 strconv
drwxr-xr-x  2 root root   333 Dec 15 07:36 strings
drwxr-xr-x  3 root root  4096 Dec 15 07:36 sync
drwxr-xr-x  3 root root 12288 Dec 15 07:36 syscall
drwxr-xr-x  5 root root   335 Dec 15 07:36 testing
drwxr-xr-x  5 root root    54 Dec 15 07:36 text
drwxr-xr-x  2 root root  4096 Dec 15 07:36 time
drwxr-xr-x  4 root root   252 Dec 15 07:36 unicode
drwxr-xr-x  2 root root    23 Dec 15 07:36 unsafe
drwxr-xr-x  3 root root    24 Dec 15 07:36 vendor

包含源代码构建脚本和标准库的包的完整源代码

6)src/cmd目录

drwxr-xr-x  2 root root   46 Dec 15 07:36 addr2line
drwxr-xr-x  3 root root   73 Dec 15 07:36 api
drwxr-xr-x  3 root root   51 Dec 15 07:36 asm
drwxr-xr-x  2 root root   38 Dec 15 07:36 buildid
drwxr-xr-x  2 root root  130 Dec 15 07:36 cgo
drwxr-xr-x  3 root root   87 Dec 15 07:36 compile
drwxr-xr-x  3 root root  121 Dec 15 07:41 cover
drwxr-xr-x  2 root root 4096 Dec 15 07:38 dist
drwxr-xr-x  3 root root   85 Dec 15 07:36 doc
drwxr-xr-x  2 root root 4096 Dec 15 07:36 fix
drwxr-xr-x  4 root root  258 Dec 15 07:43 go
drwxr-xr-x  3 root root  149 Dec 15 07:36 gofmt
drwxr-xr-x 15 root root  178 Dec 15 07:36 internal
drwxr-xr-x  3 root root  115 Dec 15 07:36 link
drwxr-xr-x  2 root root   73 Dec 15 07:36 nm
drwxr-xr-x  3 root root   60 Dec 15 07:36 objdump
drwxr-xr-x  2 root root   55 Dec 15 07:36 pack
drwxr-xr-x  2 root root   71 Dec 15 07:36 pprof
drwxr-xr-x  2 root root   21 Dec 15 07:36 test2json
drwxr-xr-x  2 root root  184 Dec 15 07:36 trace
drwxr-xr-x  4 root root   95 Dec 15 07:36 vendor
drwxr-xr-x  5 root root 4096 Dec 15 07:41 vet

包含Go和C的编辑器和命令行脚本


有疑问加站长微信联系(非本文作者)

本文来自:51CTO博客

感谢作者:Mr大表哥

查看原文:GO语言学习笔记(一)Go语言的初步了解

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

619 次点击  
加入收藏 微博
上一篇:golang学习笔记
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传