我使用 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] |
目录:[] |
哎呀。我做错了什么?
升级版:
应用程序.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
...