下面由golang教程栏目给大家介绍goland如何正确开启一个项目,希望对需要的朋友有所帮助!
因为在每次创建项目,build时都会出现error:cannot not find package,所以会有这篇文章的诞生
1. 在创建项目前的准备1.1 安装好golang,goland1.2 查看gopathecho $gopath# 如果需要更改gopath可以根据以下操作 (mac)vim ~/.bash_profileexport gopath=#你的目标地址#保存:wq#刷新source ~/.bash_profile
1.3 在$goapth文件夹中创建 pkg,bin ,src三个文件夹mkdir $gopath/pkg # pkg存放编译后的包文件mkdir $gopath/src # src存放项目源文件,我们的项目目录一般在该文件中mkdir $gopath/bin # bin存放编译后的可执行文件
可以看到我们的目录结构是这样的
$goapth |-bin |-pkg |-src |-(项目名称,之后要创建的)
1.4 开启代理 (因为国内下载包较慢或者失败,配置代理能更好的帮助我们获取第三方包)mac
vim ~/.bash_profile #打开 bash_profile# 将以下代码复制到 bash_profile 中export go111modul=on # 开启 go moduleexport goproxy=https://goproxy.io # 设置国内代理#保存:wq#刷新source ~/.bash_profile
windows
set go111modul=on # 开启 go moduleset goproxy=https://goproxy.io # 设置国内代理,推荐使用该地址
1.5 查看是否配置成功# 输入命令go env
1.6 打开goland (先不要创建项目)配置设置 setting -> plugins... -> go -> gopath
取消勾选 index entire gopath (勾选后会将当前项目作为gopath)golang会自动在 $gopath 的src目录下查找项目代码查看goland中是否也配置了代理
2.创建项目2.1根据goland的new 创建项目2.2 只需要在 $gopath/src目录下创建可以如果出现错误,可以在项目的terminal中从 1.4 开始配置以上就是goland如何正确开启一个项目的详细内容。