所以我有一个可以在localhost上正常运行的Go应用,但是我想在Google云上托管,并且云已经设置好了。整个目录树看起来像这样。
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
答案 0 :(得分:2)
如错误消息中所述,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
文件