goLand工程结构管理
开始之前请确保安装好了 go语言环境并配置好了gopath环境变量
1.创建一个新目录并打开goland选择该目录
![](https://upload-images.jianshu.io/upload_images/5606501-a0ed83abb341132e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/647/format/webp)
2.配置goland的gopath和goroot(之前配置过可省略)
打开file-settings-GO
点击GOROOT
![](https://upload-images.jianshu.io/upload_images/5606501-bbef66f78d55ff45.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
里面默认会自动选择go所在目录如果没有请手动选择一下go的安装目录
点击GOPATH
![](https://upload-images.jianshu.io/upload_images/5606501-8fc48abc7add0913.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
点击+号
![](https://upload-images.jianshu.io/upload_images/5606501-8229fdeed03f67d8.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
选择gopath目录之后点击ok
3.在该目录下创建 bin,pkg,src三个文件夹
src 目录存放的是我们的go源代码,不同工程项目的代码以包名区分。
pkg 编译后生成的文件(比如:.a)
bin bin文件夹存放go install命名生成的可执行文件
![](https://upload-images.jianshu.io/upload_images/5606501-c4368064babe979d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/507/format/webp)
4.src目录下创建一个文件夹名字可为项目名再在里面创建main.go
![](https://upload-images.jianshu.io/upload_images/5606501-8a66ed5ace87009e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/472/format/webp)
main.go里的代码
![](https://upload-images.jianshu.io/upload_images/5606501-6b3bdaeba51523c4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
5.配置运行设置
把当前目录设置为临时的gopath
再次打开file-settings-GO-gopath
![](https://upload-images.jianshu.io/upload_images/5606501-24fb8b9de35faabf.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](https://upload-images.jianshu.io/upload_images/5606501-ffaf807dfa453337.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
之后点击右上角
![](https://upload-images.jianshu.io/upload_images/5606501-be291b74ca5f4c75.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](https://upload-images.jianshu.io/upload_images/5606501-82faa1b71869fd37.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](https://upload-images.jianshu.io/upload_images/5606501-836970d9348d4b5d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
切记以单独文件运行,要以包或目录的形式运行工程
配置如下
![](https://upload-images.jianshu.io/upload_images/5606501-a45f8fa695e88736.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
Directory:该目录选择为 当前项目路径src est (test为你的项目名)
Output directory:改目录选择为当前项目路径in (生成的可执行文件将放到这个目录)
Working directory:该目录选择为 当前项目路径src est (test为你的项目名)
之后点击ok
![](https://upload-images.jianshu.io/upload_images/5606501-b6af043a2220ff0d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
点击运行
输出
![](https://upload-images.jianshu.io/upload_images/5606501-df2476a19c3cbf20.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
当前的配置 可执行文件将输出到 bin文件夹 pkg放置的是编译后的.a文件(如果你就一个main.go该文件夹为空) src就是代码文件了