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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Google App Engine 在 go 運行時找不到文件

Google App Engine 在 go 運行時找不到文件

Go
猛跑小豬 2023-06-26 16:31:56
添加 go.mod 文件后,我無法從 App Engine 上的 golang 訪問 HTML 模板文件。一切都在本地進行。我已使用 Stackdriver Debug 驗證 App Engine 上是否存在 HTML 文件,但運行時看不到它們。這是我的代碼。var templates map[string]*htmltpl.Templatefunc init() {    if templates == nil {        templates = make(map[string]*htmltpl.Template)    }    templatesDir := getTemplatesDir()    layouts, err := filepath.Glob(templatesDir + "/layouts/*.html")    if err != nil {        panic(err)    }    includes, err := filepath.Glob(templatesDir + "/includes/*.html")    if err != nil {        panic(err)    }    // Generate our templates map from our layouts/ and includes/ directories    for _, layout := range layouts {        files := append(includes, layout)        templates[filepath.Base(layout)] = htmltpl.Must(htmltpl.ParseFiles(files...))    }}func getTemplatesDir() string {    _, filename, _, ok := runtime.Caller(1)    if !ok {        panic("Could not get filename")    }    dirpath := path.Join(path.Dir(filename), "../../templates")    return dirpath}這是我的app.yaml:runtime: go111main: ./mainhandlers:  - url: .*    script: auto    secure: always這是我的目錄結(jié)構(gòu):.├── app.yaml├── db/├── go.mod├── go.sum├── handlers/├── main│   └── main.go├── middleware/├── models/├── static/├── templates/│   ├── includes│   │   ├── base.html│   │   ├── button.html│   │   ├── message.html│   │   └── profile.html│   └── layouts│       └── thread.html└── utils    └── template        └── template.go我不明白為什么在 App Engine 上,調(diào)用filepath.Glob(templatesDir + "/layouts/*.html")返回一個空切片,而它返回一個包含本地運行時的路徑的切片thread.html。
查看完整描述

1 回答

?
鴻蒙傳說

TA貢獻1865條經(jīng)驗 獲得超7個贊

該函數(shù)runtime.Caller()返回編譯時源文件路徑。該應(yīng)用程序未在與其編譯的目錄相同的目錄中運行。

應(yīng)用程序運行時當前工作目錄設(shè)置為包含 app.yaml 的目錄。使用此函數(shù)獲取模板目錄:

func getTemplatesDir() string {
    return "templates"
    }


查看完整回答
反對 回復 2023-06-26
  • 1 回答
  • 0 關(guān)注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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