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

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

在 Google App Engine 中托管 Go 項(xiàng)目時(shí)應(yīng)如何處理文件路徑?

在 Google App Engine 中托管 Go 項(xiàng)目時(shí)應(yīng)如何處理文件路徑?

Go
九州編程 2023-07-17 14:28:52
我正在嘗試在 Google 的應(yīng)用程序引擎上部署簡(jiǎn)單的 go 語(yǔ)言代碼。這是我試圖部署的代碼。 https://github.com/GoogleCloudPlatform/golang-samples/tree/master/appengine/go11x/static主程序package mainimport (    "fmt"    "html/template"    "log"    "net/http"    "os"    "path/filepath"    "time")var (    indexTmpl = template.Must(        template.ParseFiles(filepath.Join("templates", "index.html")),    ))func main() {    http.HandleFunc("/", indexHandler)    // Serve static files out of the public directory.    // By configuring a static handler in app.yaml, App Engine serves all the    // static content itself. As a result, the following two lines are in    // effect for development only.    public := http.StripPrefix("/public", http.FileServer(http.Dir("public")))    http.Handle("/public/", public)    port := os.Getenv("PORT")    if port == "" {        port = "8080"        log.Printf("Defaulting to port %s", port)    }    log.Printf("Listening on port %s", port)    log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))}// indexHandler uses a template to create an index.html.func indexHandler(w http.ResponseWriter, r *http.Request) {    if r.URL.Path != "/" {        http.NotFound(w, r)        return    }    type indexData struct {        Logo        string        Style       string        RequestTime string    }    data := indexData{        Logo:        "/public/gcp-gopher.svg",        Style:       "/public/style.css",        RequestTime: time.Now().Format(time.RFC822),    }    if err := indexTmpl.Execute(w, data); err != nil {        log.Printf("Error executing template: %v", err)        http.Error(w, "Internal server error", http.StatusInternalServerError)    }}問(wèn)題:如何處理我希望應(yīng)用程序讀取的模板和其他小文件?我的應(yīng)用程序是一個(gè)玩具應(yīng)用程序,因此我不需要云存儲(chǔ)或任何此類(lèi)解決方案。我只想從(本地)目錄中讀取內(nèi)容。
查看完整描述

1 回答

?
holdtom

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

所以...我用 3 種不同的方式測(cè)試了這個(gè)部署,我發(fā)現(xiàn):

  1. 使用 , 直接將存儲(chǔ)庫(kù)克隆到靜態(tài)文件夾,然后從那里進(jìn)行部署,重現(xiàn)了該問(wèn)題,但前提是我是從 Google Cloud Shell 執(zhí)行此操作的git clone。cd

    A。后來(lái)我發(fā)現(xiàn)我在 Cloud Shell 中使用的 Go 版本是 Go 1.12。

    b.?我創(chuàng)建了一個(gè)新的 VM 實(shí)例,以在全新的 Go 1.11 環(huán)境中對(duì)其進(jìn)行測(cè)試,并且相同的過(guò)程運(yùn)行得非常順利。

  2. 與上面的過(guò)程相同,但我沒(méi)有從靜態(tài)部署,而是將其內(nèi)容移動(dòng)到另一個(gè)目錄,然后從那里部署它。

    A。這在 VM 實(shí)例和 Cloud Shell 中有效。

  3. 根據(jù)App Engine 標(biāo)準(zhǔn)環(huán)境中的 Go 1.11 快速入門(mén)中的建議,我使用go get命令將示例代碼下載cd到靜態(tài)文件夾并從那里進(jìn)行部署。

    A。這在兩種環(huán)境中都有效。

我的建議是始終嘗試使用該go get命令下載 Google 的 golang 示例,正如指南中所建議的那樣,并且在我所做的測(cè)試中它沒(méi)有擾亂 App Engine 部署。

還值得一提的是,這兩個(gè)環(huán)境具有相同的 Cloud SDK 版本,即 259。


查看完整回答
反對(duì) 回復(fù) 2023-07-17
  • 1 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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