私はGinフレームワークを使用しています。ローカル開発モード: goapp serve すべて正常に動作します。
func init() {
route := gin.Default()
route.LoadHTMLGlob("../*/views/**/*.html")
...
}
しかし、デプロイ後:
パニック: html/テンプレート: パターンが一致するファイルがありません:
../*/views/**/*.html
わかった。私は試します:
func init() {
route := gin.Default()
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
route.LoadHTMLGlob(dir + "/../*/views/**/*.html")
...
}
同じ結果です。
私はディレクトリを取得しようとします:
...
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
...
}
c.String(http.StatusOK, "Dir: ", dir)
c.String(http.StatusOK, "\nOK")
res, err := filepath.Glob(dir + "/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v\n\n", res, err))
c.String(http.StatusOK, "Dirs:")
res, err = filepath.Glob(dir + "/**/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v", res, err))
...
結果:
ディレクトリ: %!(EXTRA string=/base/data/home/apps/tmp-LEIYJC/_ah) OK[/base/data/home/apps/tmp-LEIYJC/_ah/exe] |
ディレクトリ:[] |
おっと。私は何を間違えましたか?
更新:
app.yaml
runtime: go
api_version: go1
handlers:
- url: /images
static_dir: ../static/images
- url: /css
static_dir: ../static/css
- url: /js
static_dir: ../static/js
- url: /fonts
static_dir: ../static/fonts
- url: /.*
script: _go_app
app.yaml をサブディレクトリに配置しましたが、別の問題は発生しませんでした: [ https://groups.google.com/forum/#!topic/google-appengine-go/dNhqV6PBqVc
フォルダ構造:
app/
app.go
app.yaml
static/
...
frontend/
controllers/
UserController.go
...
models/
UserModel.go
...
views/
home/
*.html
user/
*.html
anotherfolder/
*.html
backend/
controllers/
MainController.go
...
models/
SomeModel.go
...
views/
main/
*.html
anotherfolder/
*.html
...