Go包冲突

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

Go Package Conflict

问题

我是你的中文翻译助手,以下是翻译好的内容:

我对Go和AppEngine还不熟悉。我正在尝试弄清楚如何创建包,但我一直遇到冲突。我的目录结构如下:

GOPATH
 third-party-libs 
 app 
  app.yaml
  controllers
     default.go -- 包名为controllers
   models
     models.go -- 包名为models
   templates
	 templates.go  -- 包名为templates

我在default.go中如下导入了templates包:import ("app/templates")

当我运行goapp serve时,出现以下错误:

Failed parsing input: app file templates.go conflicts with 
same file imported from GOPATH

我尝试了很多方法,但都没有成功。以下是我尝试过的方法:

  1. templates目录更改为apptemplates,相应的文件更改为apptemplates.go,包名更改为apptemplates。我将其导入为app/apptemplates

  2. 我尝试通过更改文件名但不更改包名,反之亦然等不同的组合。要么找不到文件,要么出现冲突。

  3. 我在templates.go文件中导入了html/template。所以我将整个文件注释掉,只保留包声明,但冲突问题仍然存在。

我以为可能有另一个文件名为templates.go,但当我在GOPATH级别执行以下命令时find . -name "*.go" | grep "templates.go",我只看到了我创建的一个文件。

我对如何创建包感到困惑。我已经将名称更改为通用名称,所以不像是命名问题。请问有人可以告诉我如何调试这个错误吗?

谢谢!

英文:

I am new to Go and AppEngine. I am trying to figure out how to create packages but I keep running into conflicts. My directory structure is below:

GOPATH
 third-party-libs 
 app 
  app.yaml
  controllers
     default.go -- package controllers
   models
     models.go -- package models
   templates
	 templates.go  -- package templates

I am importing the templates package as follows import ("app/templates") inside default.go

When I do goapp serve I get this error:

Failed parsing input: app file templates.go conflicts with 
same file imported from GOPATH

I have tried a bunch of things and nothing has worked so far. These are things I have tried:

  1. Changed the templates directory to apptemplates and the corresponding file to apptemplates.go, changed package name to apptemplates. I imported it as app/apptemplates

  2. I tried different combinations by changing the file name but not the package name, vice versa, etc. Either it does not find the file or has a conflict.

  3. I am importing html/template in my templates.go file. So I commented out the entire file just keeping the package declaration but did not make the conflict go away

I thought may be another file is named templates.go but when I do this (at the GOPATH level) find . -name "*.go" | grep "templates.go" I only see the one file I have created.

I am confused as to how packages are created. I have changed the name to something generic so it does not look like a naming issue. Can someone please tell me how I can debug this error?

Thanks!

答案1

得分: 4

将包重命名为与#1中的名称不冲突的名称。使用路径“apptemplates”导入该包。

应用程序目录中的包(包含app.yaml的目录)使用相对于应用程序目录的路径进行导入。有关完整详细信息,请参阅组织Go应用程序

英文:

Rename the package to a non-conflicting name as in #1. Import the package using the path "apptemplates".

Packages inside of the application directory (the directory containing app.yaml) are imported with a path relative to the application directory. See Organizing Go Apps for the complete details.

huangapple
  • 本文由 发表于 2015年1月20日 04:39:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/28033114.html
匿名

发表评论

匿名网友

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

确定