1 回答
TA贡献1790条经验 获得超9个赞
OK. It works for me with some changes.
I'm using GOPATH and so am prefixing with GO111MODULE=on. If you are outside of GOPATH, I think you can just drop the GO111MODULE=on environment setting.
Starting with directories and .go files only (no .mod files).
My path is github.com/DazWilkin/cloudfuncs.
IIUC you will need to -- minimally -- prefix module paths with example.com.
package function
import (
"fmt"
"net/http"
"github.com/DazWilkin/cloudfuncs/shared"
)
func HelloFreddie(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, shared.Hello())
}
Then, from within my cloudfuncs directory:
GO111MODULE=on go mod init github.com/DazWilkin/test
Results in a go.mod:
module github.com/DazWilkin/cloudfuncs
go 1.11
There is no go.mod file in .../cloudfuncs/shared.
Then I deploy using:
gcloud functions deploy HelloFreddie \
--region=us-central1 \
--entry-point=HelloFreddie \
--runtime=go111 \
--source=$PWD/cloudfuncs \
--project=${PROJECT} \
--trigger-http
You can see the result here: https://us-central1-dazwilkin-190225-54842789.cloudfunctions.net/HelloFreddie
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报