从Windows中导入目录

huangapple go评论109阅读模式
英文:

Importing from directory in Windows

问题

我的GOPATHC:\src\go,我有一个项目,其目录结构如下:

  1. C:\src\go\src\project\
  2. main.go
  3. folder\
  4. file1.go
  5. file2.go
  6. file3.go

其中file1.go, file2.go, file3.go有一个包名,而main.go有一个名为main的包名和main方法。在main.go中,我做了以下操作:

  1. import (
  2. "fmt"
  3. "./folder"
  4. )

但是,当我在命令行中运行go run main.go时,我收到一个错误消息,说函数未定义,因为包没有正确加载,实际上,对于包加载错误,我得到了以下错误信息:

  1. .\main.go:5: imported and not used: "_/C_/src/go/src/project/folder"

可以看到,路径并不完全正确。有什么办法在Windows中进行这种导入吗?

英文:

My GOPATH is C:\src\go, and I have a project which has the following directory structure:

  1. C:\src\go\src\project\
  2. main.go
  3. folder\
  4. file1.go
  5. file2.go
  6. file3.go

Where file1.go, file2.go, file3.go has one package name, and main.go has package name of main and the main method. In main.go I did something like this:

  1. import (
  2. "fmt"
  3. "./folder"
  4. )

But then, I run from command line go run main.go and I get an error messages that the functions are undefined, because the package is not loaded correctly, in fact for the package load error I get:

  1. .\main.go:5: imported and not used: "_/C_/src/go/src/project/folder"

where as can be seen the path is not quite correct. Any ideas how to do this import in Windows?

答案1

得分: 2

请提供您的Go源代码文件夹的完整导入路径,类似于以下形式:

  1. import (
  2. "fmt"
  3. "project/folder"
  4. )

我还强烈建议您重新组织您的GOPATH目录,以便更好地组织您的项目,并且可以更轻松地导入自己的项目。您可以参考这个链接了解更多信息:https://astaxie.gitbooks.io/build-web-application-with-golang/en/01.2.html

英文:

Include the full import path from your go source folder so something like this :

  1. import(
  2. "fmt"
  3. "project/folder"
  4. )

I also highly recommend you restructure your GOPATH directory for organisation purposes so you can find importing your own projects much easier. https://astaxie.gitbooks.io/build-web-application-with-golang/en/01.2.html

huangapple
  • 本文由 发表于 2017年6月12日 03:40:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/44488012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定