英文:
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
我尝试了很多方法,但都没有成功。以下是我尝试过的方法:
-
将
templates
目录更改为apptemplates
,相应的文件更改为apptemplates.go
,包名更改为apptemplates
。我将其导入为app/apptemplates
。 -
我尝试通过更改文件名但不更改包名,反之亦然等不同的组合。要么找不到文件,要么出现冲突。
-
我在
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:
-
Changed the
templates
directory toapptemplates
and the corresponding file toapptemplates.go
, changed package name toapptemplates
. I imported it asapp/apptemplates
-
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.
-
I am importing
html/template
in mytemplates.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论