简体   繁体   English

如何将新文件添加到Go项目

[英]How to add new file to Go project

I am using the Go plugin for IntelliJ Idea. 我正在使用IntelliJ Idea的Go插件。

I'm not sure how I got my project working like this but I am able to run my Main.go file and it includes all my other files in the project that I can reference. 我不确定如何使我的项目像这样工作,但是我能够运行Main.go文件,并且该文件包括项目中我可以引用的所有其他文件。 That is perfect. 太好了

The problem now is that when I go and create a new "*.go" file it's not included in the IDE build and I get compiled errors wherever I refer to the contents of that file. 现在的问题是,当我去创建一个新的“ * .go”文件时,它不包含在IDE版本中,无论我引用该文件的内容在哪里,都会出现编译错误。

How can I fix this? 我怎样才能解决这个问题?

i think you can set GOPATH in the ~/.bash_profile, eg GOPATH=~/code/go export GOPATH 我认为您可以在〜/ .bash_profile中设置GOPATH,例如GOPATH =〜/ code / go export GOPATH

and source ~/.bash_profile or restart the terminal. 并找到〜/ .bash_profile或重新启动终端。 it will go to effect; 它将生效;

then put *.go or go project related with the main.go under the GOPATH. 然后将* .go或与main.go相关的go项目放在GOPATH下。

finally, main.go will find the *.go. 最终,main.go将找到* .go。

There are two types of run configurations for Go applications: - Go Single file -> which is the equivalent of go run file.go - Go Application -> which is the equivalent of go build file / package and run the binary Go应用程序有两种类型的运行配置:-Go单个文件->等效于go run file.go-Go应用程序->等效于go build文件/程序包并运行二进制文件

By the sound of it, you want to run a Go Application with Run kind set to package. 听起来,您想运行将Run种设置为package的Go Application。 There you'll need to type the full package name, for example: github.com/dlsniper/demo/cmd/democmd At the moment support for running multiple files / building a directory is not present (there are some issues opened for it) 在那里,您需要输入完整的软件包名称,例如:github.com/dlsniper/demo/cmd/democmd目前不支持运行多个文件/构建目录(为此打开了一些问题)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM