douyan3478 2016-04-09 16:15
浏览 44

google app引擎文件冲突golang

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条回答 默认 最新

  • dpf25323 2016-08-02 21:13
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机数字电压表电路组成及框图
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line