尝试使用Go模块在Go 1.11中部署Google Cloud功能时出错 [英] Error when trying to deploy Google cloud function in Go 1.11 using go modules

查看:207
本文介绍了尝试使用Go模块在Go 1.11中部署Google Cloud功能时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用Go模块在Go 1.11中部署Google云功能时遇到问题.我的GOPATH中具有以下代码结构:

I am having issues trying to deploy a Google cloud function in Go 1.11 using Go modules. I have have the following code structure in my GOPATH:

└── example
    ├── models
    │   ├── go.mod
    │   └── models.go
    └── load
        ├── fn.go
        ├── go.mod
        ├── go.sum
        └── vendor
            └── ....

load/go.mod如下所示:

the load/go.mod looks like the following:

module github.com/example/load

require (
    github.com/example/models v0.0.0
)

replace github.com/example/models => ../models

当我尝试使用命令部署功能时

When I try to deploy the function using the command

gcloud functions deploy load-data --entry-point GCSNewFileTrigger --runtime go111 --trigger-resource new_data --trigger-event google.storage.object.finalize

我收到以下错误:

Deploying function (may take a while - up to 2 minutes)...failed.                                                                                                                                                                     
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory
go: error loading module requirements

命令go mod vendorgo mod verify在本地成功运行,我可以在load的供应商文件夹中看到我的本地软件包models.

The commands go mod vendor and go mod verify run successfully locally and I can see my local package models in the vendor folder of load

推荐答案

与供应商相比,构建器更喜欢使用模块.如果有go.mod,将使用模块.当您上载函数时,它仅包含函数所在目录的目录,而不包含上一级目录.因此,当有go.mod且您有一个指向上一级的replace指令时,它将不起作用.

Modules are preferred by the builder over vendor. If there is a go.mod, modules will be used. When you upload your function, it only includes the directory with your function at the root, not any directories one level up. So, when there is a go.mod and you have a replace directive pointing one level up, it will not work.

解决方案是针对供应商,而不是上载go.mod/go.sum文件.使用gcloud时,您可以创建一个.gcloudignore文件来为您执行此操作.请参见 https://cloud.google.com/functions/docs/concepts/请转到go-runtime#specifying_dependencies 了解详情.

The solution is to vendor and not upload the go.mod/go.sum files. When using gcloud, you can create a .gcloudignore file to do this for you. See https://cloud.google.com/functions/docs/concepts/go-runtime#specifying_dependencies for more detail.

免责声明:我在Google和此产品上工作.

Disclaimer: I work at Google and on this product.

这篇关于尝试使用Go模块在Go 1.11中部署Google Cloud功能时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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