Deploying Google Cloud Function with Go Modules Error
When attempting to deploy a Google Cloud Function in Go 1.11 using Go modules, developers may encounter the error, "Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory."
Go Module Structure
Go modules prefer modules over vendors, which can lead to the error if a go.mod file is present with a replace directive pointing one level up. The function upload only includes the directory with the function at the root, not the directories one level up.
Solution
To resolve this issue, avoid uploading the go.mod/go.sum files and use vendor instead. With gcloud, create a .gcloudignore file to ignore these files during upload. For more details, refer to the Google Cloud documentation (link provided in the answer).
The above is the detailed content of How to Resolve \'Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory\' Error When Deploying Go Cloud Functions with Go Modules?. For more information, please follow other related articles on the PHP Chinese website!