今天我给大家带来《解析 go.mod 时出错 如何使用云构建在 App Engine 上部署 go 应用程序?》,这篇文章主要讲到等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!
问题内容
所以我有这个 go 应用程序,它在本地主机上运行良好,但我想托管在谷歌云上,并且云已经设置好了。整个目录树看起来像这样。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
gocode
---bin
---pkg
---src
---cloud.google.com
---github.com
...
---appname
---auth
---database
...
---main.go
---app.yaml
---cloudbuild.yaml
---go.mod
这是app.yaml
1
2
3
4
5
6
runtime: go112
api_version: go1
handlers:
- url: /.*
script: _go_app
这是cloudbuild.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
1
2
3
module github.com/raj-varun/appname-api/
require github.com/spf13/viper
当我运行 gcloud builds submit --config cloudbuild.yaml . 时,我收到此错误
1
2
3
4
5
6
7
8
9
10
11
12
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 中,你有这个:
1
require github.com/spf13/viper
您有 module/path 但没有版本!
Go the the viper github project and take the release version that you want。例如
1
require github.com/spf13/viper v1.4.0
您还可以尝试执行 go mod tidy 来自动构建和清理 go.mod 文件
终于介绍完啦!小伙伴们,这篇关于《解析 go.mod 时出错 如何使用云构建在 App Engine 上部署 go 应用程序?》的介绍应该让你收获多多了吧!
