google app engine file conflict golang

2019-05-21 13:27发布

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.

1条回答
beautiful°
2楼-- · 2019-05-21 14:00

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

查看更多
登录 后发表回答