组织Go的源码
2015-10-08 22:17
387 查看
工作空间(workspace)
在开始编写代码前,要先创建一个文件夹作为工作空间,工作空间文件夹里包含三个子文件夹
src 存放Go源码,以package的形式组织源码,每个package对应一个文件夹
pkg 类库编译后的二进制文件(*.a)存放在该文件夹里
bin 执行go install命令后,最终编译好的可执行文件会存放在该文件夹里
设置环境变量
变量GOPATH指向工作空间所在的目录,并把$GOPATH/bin加入PATH变量中
变量GOROOT指向Go的安装路径,并把$GOROOT/bin加入PATH变量中
在编译Go源码时,会先去$GOROOT/src查找所需的package,如果找不到则查找$GOPATH/src
package
Go源码文件的第一行必须是声明package
where name is the package's default name for imports. (All files in a package must use the same name.)
Go's convention is that the package name is the last element of the import path: the package imported as "crypto/rot13" should be named rot13.
可执行的程序必须使用package main
There is no requirement that package names be unique across all packages linked into a single binary, only that the import paths (their full file names) be unique.
官方详细说明
在开始编写代码前,要先创建一个文件夹作为工作空间,工作空间文件夹里包含三个子文件夹
src 存放Go源码,以package的形式组织源码,每个package对应一个文件夹
pkg 类库编译后的二进制文件(*.a)存放在该文件夹里
bin 执行go install命令后,最终编译好的可执行文件会存放在该文件夹里
设置环境变量
变量GOPATH指向工作空间所在的目录,并把$GOPATH/bin加入PATH变量中
变量GOROOT指向Go的安装路径,并把$GOROOT/bin加入PATH变量中
在编译Go源码时,会先去$GOROOT/src查找所需的package,如果找不到则查找$GOPATH/src
package
Go源码文件的第一行必须是声明package
package name
where name is the package's default name for imports. (All files in a package must use the same name.)
Go's convention is that the package name is the last element of the import path: the package imported as "crypto/rot13" should be named rot13.
可执行的程序必须使用package main
There is no requirement that package names be unique across all packages linked into a single binary, only that the import paths (their full file names) be unique.
官方详细说明
相关文章推荐
- 【PAT】1096. Consecutive Factors (20)
- Django中关于url的用法
- django 分拆url文件
- django 模板找不到TemplateDoesNotExist报错!
- go语法
- Go语言学习笔记、Go和C++区别
- Algorithms—89.Gray Code
- ZOJ 3197 Google Book
- 【期望dp】LightOJ 1030 Discovering Gold
- django 学习资料
- mongoose
- Algorithms—229.Majority Element II
- LSGO软件技术团队2015~2016学年第三周(0914~0920)总结
- Algorithms—287.Find the Duplicate Number
- django模型修改后更新报错表不存在的的解决办法
- Go语言学习笔记
- Algorithms—290.Word Pattern
- 谷歌推出加速移动网页项目AMP:打开网页速度更快
- Emacs中Golang的设置
- django filefield实现动态改变文件上传位置upload_to