google-app-engine - 去包冲突

标签 google-app-engine go

我是 Go 和 AppEngine 的新手。我试图弄清楚如何创建包,但我一直遇到冲突。我的目录结构如下:

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

我在 default.go 中按如下方式导入模板包 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 . -名称“*.go” | grep "templates.go" 我只看到我创建的一个文件。

我对包的创建方式感到困惑。我已将名称更改为通用名称,因此它看起来不像是命名问题。有人可以告诉我如何调试此错误吗?

谢谢!

最佳答案

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

应用程序目录(包含 app.yaml 的目录)内的包使用相对于应用程序目录的路径导入。参见 Organizing Go Apps了解完整详情。

关于google-app-engine - 去包冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28033114/

相关文章:

go - 可汗学院重定向默认 URL Golang

go - 为什么 golang 将类型说明符 "after"放在变量名中?

sql - GO 中这个错误 `update or delete on table "tablename"violates foreign key constraint"的名称是什么?

unit-testing - 如何在执行所有 go 测试文件之前从 .yaml 文件加载配置?

testing - 从 panic 中恢复的主要和测试之间的区别?

python - 在 App Engine Python 中动态向 Google Datastore 实体添加属性(灵活环境)

python - 如何将 Polymer 项目引入 Google App Engine

java - Spring 可以缓存组件扫描信息/ Autowiring 以缩短启动时间吗?

java - 使用 Dockerfile (IntelliJ) 部署 Google 灵活应用引擎

google-app-engine - 从 python ndb 客户端读取嵌入式实体