在go 1.7中使用嵌套的供应商目录

在go 1.7中使用嵌套的供应商目录,go,Go,我有一个go项目,包含以下软件包:- go list ./... | grep -v /vendor/ github.com/jab/JSes github.com/jab/JSes/src/common/config github.com/jab/JSes/src/common/logger github.com/jab/JSes/src/common/monitor github.com/jab/JSes/src/handlers/healthcheck github.com/jab/J

我有一个go项目,包含以下软件包:-

go list ./... | grep -v /vendor/ 

github.com/jab/JSes
github.com/jab/JSes/src/common/config
github.com/jab/JSes/src/common/logger
github.com/jab/JSes/src/common/monitor
github.com/jab/JSes/src/handlers/healthcheck
github.com/jab/JSes/src/handlers/sessionuser
github.com/jab/JSes/src/test/servicetest
ses-ser
    vendor   //Contains all the external dependencies
    api
    constants
    exceptions
    idgen
    jsonDecoder
    log
    model
    monitor
    persistence
    redis
    routes
    src/bddtest/servicetest
    util
所有外部从属关系都添加到供应商文件夹中:-

现在,ses ser具有以下软件包:-

go list ./... | grep -v /vendor/ 

github.com/jab/JSes
github.com/jab/JSes/src/common/config
github.com/jab/JSes/src/common/logger
github.com/jab/JSes/src/common/monitor
github.com/jab/JSes/src/handlers/healthcheck
github.com/jab/JSes/src/handlers/sessionuser
github.com/jab/JSes/src/test/servicetest
ses-ser
    vendor   //Contains all the external dependencies
    api
    constants
    exceptions
    idgen
    jsonDecoder
    log
    model
    monitor
    persistence
    redis
    routes
    src/bddtest/servicetest
    util
生成文件如下所示:-

.PHONY: deploy

LOGLEVEL ?= 2
GOFLAGS ?= $(GOFLAGS:)

PKG = $(shell go list ./... | grep -v /vendor/ | tr "\n" " ")
PWD = $(shell pwd)

export GOPATH = $(PWD):$(shell echo $$GOPATH)
export GOBIN = $(PWD)/bin
export GOROOT = $(shell echo $$GOROOT)

deploy: clean format build install conf

build:
    @rm -rf pkg/ 2>/dev/null
    @rm -rf _libs/pkg/ 2>/dev/null
    @go build $(GOFLAGS) $(PKG)
export GOPATH = $(PWD)/_libs:$(PWD)/_libs/src/bitbucket.org/m/ses-ser/vendor:$(PWD):$(shell echo $$GOPATH). 
src/handlers/healthcheck/health_check.go:23: cannot use func literal (type func(*"github.com/valyala/fasthttp".RequestCtx)) as type func(*"bitbucket.org/m/ses-ser/vendor/github.com/valyala/fasthttp".RequestCtx) in field value
但在进行“建造”时,我感到了以下恐慌:-

jab-MacBook-Pro-4:JSe debraj$ make build
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0x3e1b40, 0xc420010130)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1
main.vendoredImportPath(0xc4203df200, 0xc42037f301, 0x2f, 0x3, 0xc41fff4f00)
    /usr/local/go/src/cmd/go/pkg.go:463 +0x66c
main.loadImport(0xc42037f301, 0x2f, 0xc4201605b0, 0x64, 0xc4203df200, 0xc4201c99e0, 0xc42022f680, 0x1, 0x1, 0x1, ...)
    /usr/local/go/src/cmd/go/pkg.go:333 +0x9ea
main.(*Package).load(0xc4203df200, 0xc4201c99e0, 0xc420298e00, 0x0, 0x0, 0x4)
    /usr/local/go/src/cmd/go/pkg.go:940 +0x12b6
main.loadImport(0xc420356f01, 0x29, 0xc4203203c0, 0x45, 0xc4203de480, 0xc4201c99e0, 0xc4203570e0, 0x1, 0x1, 0x1, ...)
    /usr/local/go/src/cmd/go/pkg.go:374 +0x470
main.(*Package).load(0xc4203de480, 0xc4201c99e0, 0xc420293c00, 0x0, 0x0, 0x4)
    /usr/local/go/src/cmd/go/pkg.go:940 +0x12b6
main.loadImport(0xc42019c6b1, 0xd, 0xc42019e7c0, 0x33, 0xc4201ac480, 0xc4201c99e0, 0xc420192e70, 0x1, 0x1, 0x1, ...)
    /usr/local/go/src/cmd/go/pkg.go:374 +0x470
main.(*Package).load(0xc4201ac480, 0xc4201c99e0, 0xc420185180, 0x0, 0x0, 0xc)
    /usr/local/go/src/cmd/go/pkg.go:940 +0x12b6
main.loadImport(0x7fff5fbff891, 0x1a, 0xc420018044, 0x33, 0x0, 0xc4201c99e0, 0x0, 0x0, 0x0, 0x0, ...)
    /usr/local/go/src/cmd/go/pkg.go:374 +0x470
main.loadPackage(0x7fff5fbff891, 0x1a, 0xc4201c99e0, 0x0)
    /usr/local/go/src/cmd/go/pkg.go:1658 +0x28f
main.packagesAndErrors(0xc420152c80, 0x7, 0x7, 0xc42019c520, 0x20, 0x3f3e60)
    /usr/local/go/src/cmd/go/pkg.go:1703 +0x337
main.packagesForBuild(0xc42000c0b0, 0x7, 0x7, 0x493df8, 0xc420018180, 0x0)
    /usr/local/go/src/cmd/go/pkg.go:1719 +0x75
main.runBuild(0x628540, 0xc42000c0b0, 0x7, 0x7)
    /usr/local/go/src/cmd/go/build.go:440 +0xd4
main.main()
    /usr/local/go/src/cmd/go/main.go:181 +0x624
make: *** [build] Error 2
这似乎与将在Go 1.8中修复的问题有关

作为一种解决方法,我尝试将所有外部依赖项置于libs下。并在Makefile中修改了我的$GOPATH,如下所示:-

.PHONY: deploy

LOGLEVEL ?= 2
GOFLAGS ?= $(GOFLAGS:)

PKG = $(shell go list ./... | grep -v /vendor/ | tr "\n" " ")
PWD = $(shell pwd)

export GOPATH = $(PWD):$(shell echo $$GOPATH)
export GOBIN = $(PWD)/bin
export GOROOT = $(shell echo $$GOROOT)

deploy: clean format build install conf

build:
    @rm -rf pkg/ 2>/dev/null
    @rm -rf _libs/pkg/ 2>/dev/null
    @go build $(GOFLAGS) $(PKG)
export GOPATH = $(PWD)/_libs:$(PWD)/_libs/src/bitbucket.org/m/ses-ser/vendor:$(PWD):$(shell echo $$GOPATH). 
src/handlers/healthcheck/health_check.go:23: cannot use func literal (type func(*"github.com/valyala/fasthttp".RequestCtx)) as type func(*"bitbucket.org/m/ses-ser/vendor/github.com/valyala/fasthttp".RequestCtx) in field value
但随后它开始给我如下错误:-

.PHONY: deploy

LOGLEVEL ?= 2
GOFLAGS ?= $(GOFLAGS:)

PKG = $(shell go list ./... | grep -v /vendor/ | tr "\n" " ")
PWD = $(shell pwd)

export GOPATH = $(PWD):$(shell echo $$GOPATH)
export GOBIN = $(PWD)/bin
export GOROOT = $(shell echo $$GOROOT)

deploy: clean format build install conf

build:
    @rm -rf pkg/ 2>/dev/null
    @rm -rf _libs/pkg/ 2>/dev/null
    @go build $(GOFLAGS) $(PKG)
export GOPATH = $(PWD)/_libs:$(PWD)/_libs/src/bitbucket.org/m/ses-ser/vendor:$(PWD):$(shell echo $$GOPATH). 
src/handlers/healthcheck/health_check.go:23: cannot use func literal (type func(*"github.com/valyala/fasthttp".RequestCtx)) as type func(*"bitbucket.org/m/ses-ser/vendor/github.com/valyala/fasthttp".RequestCtx) in field value
有人能提出一些解决这个问题的办法吗

环境:-

go版本go1.7.3达尔文/amd64 Mac OS X-版本10.11.6
虽然构建恐慌是一个已经修复的bug,但是嵌套的供应商目录将导致包之间的类型冲突

您的项目应该只有一个供应商目录。如果您的任何依赖项都有自己的供应商目录,则应将它们剥离并合并到您的单个顶级供应商目录中


为提供依赖项而设计的工具应该为您做到这一点

你不应该有嵌套的供应商目录。如果同一个包被多次出售,这也会导致类型不匹配。ses-ver是我试图用作JSE依赖项的包,并且ses-ver的所有依赖项都位于供应商之下。因此,我在JSes中的供应商下添加了ses ver。那么我该如何解决这个问题呢?您可以手动或通过govendor或godep等工具将所有供应商的依赖关系展平到顶层。您是否建议我将ses ser/供应商下的所有依赖关系移动到JSes/供应商并删除ses ser/供应商?但是它可以嵌套在ses ver的一个依赖项本身有一个供应商的地方。您的任何依赖项都不应该有供应商目录,如果有,您需要将它们协调到项目的供应商目录中。我也遇到了这个问题,并最终使用了glide工具,因为它包含安装依赖项的带供应商标志。