谷歌应用程序引擎文件冲突golang [英] google app engine file conflict golang

查看:205
本文介绍了谷歌应用程序引擎文件冲突golang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图用谷歌的应用程序引擎来运行我的应用程序。当我运行 goapp server 时出现此错误:

  go-app -builder:解析输入失败:应用程序文件model.go与从GOPATH导入的相同文件冲突

这是我的项目布局:

 
├──model
│└──model.go
├──reqres
│└──reqres.go
├──app.yaml
├──service.go
├──main.go
└──transport.go

如果我在没有应用程序引擎的情况下运行它,我不会收到任何错误并且应用程序运行良好。

解决方案

<根据我的经验,你会得到这个错误,因为你的项目文件夹也在你的GOPATH下。 goapp类型的克隆你的项目文件夹,并建立它去对环境GOPATH和GOROOT ...这样做,它会发现你已经在你的项目下宣布的所有包的重复符号。



以下是转到appengine文档 a>


如果你在GOPATH中包含你的包源代码,你必须小心,不要将源代码放在你的任何目录下包含app.yaml文件的App Engine项目。如果发生这种情况,一个包可以加载两次,一次是相对于模块目录的路径,一次是完全限定路径。这可能会导致一些细微的问题,因此Go SDK会扫描您的项目和GOPATH,检测到此案例并将其报告为错误。

在相同的链接下,你会发现一些建议由谷歌为您的项目结构,其中之一是(您的项目打破该准则):


不要在模块的目录中包含任何子目录。


如果您想要一个包含您的应用程序定义和软件包的存储库,我鼓励您采用以下结构:

  projectRoot 
| - 模块
| | - myModule1
| | | - init.go //路由器模式处理
| | | - myModule1.yaml //模块
|的配置| - myModule2
| | - init.go //路由器模式处理
| | - myModule2.yaml //模块
|的配置
| - pkg
| | - myModule1
| | | - * .go //来源,子文件夹(包)
| | //使用处理程序和业务代码
| | - myModule2
| | | - * .go //源文件,子文件夹(包)
//包含处理程序和业务代码

这篇文章的结构非常简单,并且改善了调试体验,正如文章调试使用visual studio代码转到appengine模块


So I'm trying to run my go app with google's app engine. When I run goapp server I get this error:

go-app-builder: Failed parsing input: app file model.go conflicts with same file imported from GOPATH

This is my project layout:

.
├── model
│   └── model.go
├── reqres
│   └── reqres.go
├── app.yaml
├── service.go
├── main.go
└── transport.go

If I run it without app engine I don't any get errors and the app runs fine.

解决方案

According to my experience you get this error because your project folder is also under your GOPATH. "goapp" kind of clone your project folder and builds it against the go environment GOPATH and GOROOT... Doing so it finds duplicated symbols for all package that you have been declared under your project.

Here is the explanation in go appengine documentation

If you include your package sources in GOPATH, you must be careful not to place the source code at or below any directories in your App Engine project that contain app.yaml files. If that happens, a package could be loaded twice, once for the path relative to a module's directory, and once for the fully-qualified path. This can cause subtle problems, so the Go SDK scans your project and your GOPATH, detects this case, and reports it as an error.

Under the same link you will find some advises by google for your project structure and one of them is (your project break that guideline):

Do not include any subdirectories in a module's directory.

If you want a repository with your application definition and go packages I encourage you to adopt the folliwing structure:

projectRoot
   |- modules
   |   |- myModule1
   |   |    |- init.go        // router pattern to handler
   |   |    |- myModule1.yaml // configuration for the module
   |   |- myModule2
   |        |- init.go        // router pattern to handler
   |        |- myModule2.yaml // configuration for the module
   |    
   |- pkg
   |   |- myModule1
   |   |    |- *.go           // sources, subfolders(packages)
   |   |                      // with handlers and business code
   |   |- myModule2
   |   |    |- *.go           // sources, subfolders(packages)
                              // with handlers and business code

This structure is convinient and improves debugging experience as explained in the article debugging Go appengine module with visual studio code

这篇关于谷歌应用程序引擎文件冲突golang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆