登录
首页 >  Golang >  Go问答

解析 go.mod 时出错 如何使用云构建在 App Engine 上部署 go 应用程序?

来源:stackoverflow

时间:2024-04-20 16:06:35 303浏览 收藏

欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《解析 go.mod 时出错 如何使用云构建在 App Engine 上部署 go 应用程序?》,这篇文章主要讲到等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!

问题内容

所以我有这个 go 应用程序,它在本地主机上运行良好,但我想托管在谷歌云上,并且云已经设置好了。整个目录树看起来像这样。

gocode
---bin
---pkg
---src
  ---cloud.google.com
  ---github.com
  ...
  ---appname
    ---auth
    ---database
    ...
    ---main.go
    ---app.yaml
    ---cloudbuild.yaml
    ---go.mod

这是app.yaml

runtime: go112
api_version: go1

handlers:
- url: /.*
  script: _go_app

这是cloudbuild.yaml

steps:

- name: 'golang'
  args: ['go', 'build', '.']
  env: ['go111module=on']

- name: 'gcr.io/cloud-builders/go'
  args: ['get', '-d', 'appname']
  env: ['gopath=/gopath/','mode=dev']
  volumes:
  - name: 'go'
    path: '/gopath'

- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy']
  env: ['gopath=/gopath/','mode=dev']
  volumes:
  - name: 'go'
    path: '/gopath'

这是go.mod

module github.com/raj-varun/appname-api/

require github.com/spf13/viper

当我运行 gcloud builds submit --config cloudbuild.yaml . 时,我收到此错误

tarting Step #0
Step #0: Pulling image: golang
Step #0: Using default tag: latest
Step #0: latest: Pulling from library/golang
Step #0: Digest: sha256:a50a9364e9170ab5f5b03389ed33b9271b4a7b6bbb0ab41c4035adb3078927bc
Step #0: Status: Downloaded newer image for golang:latest
Step #0: docker.io/library/golang:latest
Step #0: go: errors parsing go.mod:
Step #0: /workspace/go.mod:3: usage: require module/path v1.2.3
Finished Step #0
ERROR
ERROR: build step 0 "golang" failed: exit status 1

解决方案


如错误消息中所述,require 包路径必须采用以下格式 require module/path v1.2.3

在你的 go.mod 中,你有这个:

require github.com/spf13/viper

您有 module/path 但没有版本!

Go the the viper github project and take the release version that you want。例如

require github.com/spf13/viper v1.4.0

您还可以尝试执行 go mod tidy 来自动构建和清理 go.mod 文件

终于介绍完啦!小伙伴们,这篇关于《解析 go.mod 时出错 如何使用云构建在 App Engine 上部署 go 应用程序?》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>