Home > Backend Development > Golang > How to start a project correctly in Goland

How to start a project correctly in Goland

藏色散人
Release: 2021-06-08 15:18:15
forward
3609 people have browsed it

The following tutorial column from golang will introduce to you how to correctly start a project in Goland. I hope it will be helpful to friends in need!

Because Error: cannot not find package will appear every time you create a project and build, so this article was born

1. Preparation before creating the project

1.1 Installgolang,goland

1.2 View GOPATH

echo $GOPATH# 如果需要更改GOPATH可以根据以下操作 (Mac)vim ~/.bash_profileexport GOPATH=#你的目标地址
#保存:wq
#刷新
source ~/.bash_profile
Copy after login

1.3 Create pkg,bin## in the $GOAPTH folder #,srcThree folders
mkdir $GOPATH/pkg  # pkg存放编译后的包文件
mkdir $GOPATH/src  # src存放项目源文件,我们的项目目录一般在该文件中
mkdir $GOPATH/bin  # bin存放编译后的可执行文件
Copy after login

You can see that our directory structure is like this

$GOAPTH
    |-bin    |-pkg    |-src       |-(项目名称,之后要创建的)
Copy after login

1.4 Turn on the proxy (because of domestic downloads The package is slow or fails. Configuring the proxy can better help us obtain third-party packages)

Mac

vim ~/.bash_profile #打开 bash_profile

# 将以下代码复制到 bash_profile 中export GO111MODUL=on  # 开启 go moduleexport GOPROXY=https://goproxy.io  # 设置国内代理

#保存:wq

#刷新
source ~/.bash_profile
Copy after login

Windows

set GO111MODUL=on  # 开启 go moduleset GOPROXY=https://goproxy.io  # 设置国内代理,推荐使用该地址
Copy after login

1.5 Check whether the configuration is successful
# 输入命令
go env
Copy after login

1.6 Open Goland (don’t create a project yet)

    Configuration settings
  • Setting -> Plugins... -> Go -> GOPATH
    How to start a project correctly in Goland##Uncheck
  • index entire GOPATH
  • (After checking, the current Project as GOPATH)Golang will automatically search for the project code in the
  • src
  • directory of $GOPATHCheck whether the agent is also configured in Goland

How to start a project correctly in Goland

2. Create a project

2.1 Create a project based on Goland’s new

2.2 You only need to create it in the $GOPATH/src directory.

If an error occurs, you can create it in the
    Terminal
  • of the project. Configuration starting from 1.4

The above is the detailed content of How to start a project correctly in Goland. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template