gpt4 book ai didi

google-app-engine - 谷歌应用引擎文件冲突golang

转载 作者:IT王子 更新时间:2023-10-29 01:39:12 33 4
gpt4 key购买 nike

所以我正在尝试使用谷歌的应用引擎运行我的 go 应用程序。当我运行 goapp server 时出现此错误:

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

这是我的项目布局:

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

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

最佳答案

根据我的经验,您会收到此错误,因为您的项目文件夹也在您的 GOPATH 下。 “goapp” 克隆您的项目文件夹并针对 go 环境 GOPATH 和 GOROOT 构建它...这样做它会为您在项目下声明的所有包找到重复的符号。

这是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.

在同一链接下,您会发现 google 对您的项目结构的一些建议,其中之一是(您的项目违反了该准则):

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

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

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

如文章 debugging Go appengine module with visual studio code 中所述,此结构很方便并改善了调试体验

关于google-app-engine - 谷歌应用引擎文件冲突golang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36519427/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com