第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

當(dāng)源代碼包含多個(gè)級別/目錄時(shí)部署 Google Cloud Function

當(dāng)源代碼包含多個(gè)級別/目錄時(shí)部署 Google Cloud Function

Go
手掌心 2023-06-12 10:06:37
我想部署一個(gè)用 Go 編寫的 Google Cloud Function,其代碼結(jié)構(gòu)包含一個(gè)子目錄,如下所示:function├── module1│   ├── go.mod│   └── module1.go├── go.mod└── entrypoint.go但是當(dāng)我部署函數(shù)時(shí),使用 GCP 控制臺(tái)或gcloud命令:# from function/ directorygcloud functions deploy myfunction --runtime go111 [...]僅go.mod和entrypoint.go已上傳(我檢查了GCP 控制臺(tái)中函數(shù)詳細(xì)信息的源選項(xiàng)卡)。因此該函數(shù)無法部署,因?yàn)轱@然使用了.entrypoint.gomodule1/module1.go如果源是.zipGoogle Cloud Storage 上的一個(gè)(包含多個(gè)目錄),也會(huì)發(fā)生同樣的情況:gcloud functions deploy myfunction \    --runtime go111 \    --source gs://${BUCKET}/function.zip [...]是否可以使用帶有子目錄的代碼結(jié)構(gòu)來部署函數(shù)?我不知道其他運(yùn)行時(shí)(Python、NodeJS)是否也會(huì)發(fā)生同樣的情況,或者該問題是否特定于 Go。編輯我試著遵循這個(gè)指南:https://cloud.google.com/functions/docs/writing/#functions-writing-file-structuring-go(第二點(diǎn):項(xiàng)目根目錄下的一個(gè)包,它從子包并導(dǎo)出一個(gè)或多個(gè)函數(shù)),如評論中所建議的那樣,但沒有成功。這是我使用的結(jié)構(gòu)(在本地工作):.├── function.go├── go.mod└── shared    ├── go.mod    └── shared.gogo.modmodule testcloudfunctionrequire testcloudfunction/shared v0.0.0replace testcloudfunction/shared => ./shared函數(shù).gopackage functionimport (    "fmt"    "testcloudfunction/shared")func HelloWorld(w http.ResponseWriter, r *http.Request) {    fmt.Fprint(w, shared.Hello())}共享/go.modmodule testcloudfunction/shared共享/shared.gopackage sharedfunc Hello() string {    return "Hello World!"}
查看完整描述

1 回答

?
富國滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

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


查看完整回答
反對 回復(fù) 2023-06-12
  • 1 回答
  • 0 關(guān)注
  • 146 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號