gcloud函数部署出现运行时错误 “undefined: unsafe.Slice; 错误ID: 2f5e35a0”

huangapple go评论72阅读模式
英文:

gcloud functions deploy go runtime error "undefined: unsafe.Slice; Error ID: 2f5e35a0"

问题

在部署到Google Cloud Function时,我遇到了这个错误:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: # projectname/vendor/golang.org/x/sys/unix
src/projectname/vendor/golang.org/x/sys/unix/syscall.go:83:16: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice; Error ID: 2f5e35a0

这是我的命令:

gcloud functions deploy servicename --region=us-central1 --entry-point=gofunctionname --runtime=go116 --source=.

我正在使用vendoring来打包我的依赖项。我已经有一段时间没有更新这个函数了。这是我第一次注意到这个错误。

非常感谢任何帮助。

英文:

While deploying to google cloud function, I am getting this error:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: # projectname/vendor/golang.org/x/sys/unix
src/projectname/vendor/golang.org/x/sys/unix/syscall.go:83:16: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice; Error ID: 2f5e35a0

Here's my command:

gcloud functions deploy servicename --region=us-central1 --entry-point=gofunctionname --runtime=go116 --source=.

I am using vendoring to package my dependencies. It's been a while I have updated this function. And first time I noticed this error.

Any help would be much appreciated.

答案1

得分: 10

根据DazWilkin的建议,unsafe.Slice是作为Go 1.17的一部分添加的,而GCP Functions目前支持Go 1.16。

我不得不在go.mod文件中将golang.org/x/sys模块还原,这对我起作用了。

golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect

golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect

通过这个更改,我能够构建和部署代码到Google Cloud Functions。

英文:

As DazWilkin suggested above, unsafe.Slice was added as part of Go 1.17 and GCP Functions support Go 1.16 as of now.

I had to revert back the golang.org/x/sys module in the go.mod file and it worked for me.

From

golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect

To

golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect

With this change, I am able to build and deploy the code to Google Cloud Functions.

答案2

得分: 1

截至撰写本文时,Google Cloud Functions现在支持Go 1.18和Go 1.19。

将您的项目更新为go119,您就不应该再遇到这个问题了。例如:

gcloud functions deploy servicename --runtime=go119 --region=us-central1
英文:

As of the time of writing this, Google Cloud Functions now supports Go 1.18 and Go 1.19.

Update your project to go119 and you shouldn't have this issue anymore. For example:

gcloud functions deploy servicename --runtime=go119 --region=us-central1 

huangapple
  • 本文由 发表于 2022年10月13日 08:47:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/74049351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定