Reputation: 688
I using Gin framework. At local development mode: goapp serve all works fine.
func init() {
route := gin.Default()
route.LoadHTMLGlob("../*/views/**/*.html")
...
}
But after deploy:
panic: html/template: pattern matches no files:
../*/views/**/*.html
OK. I try:
func init() {
route := gin.Default()
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
route.LoadHTMLGlob(dir + "/../*/views/**/*.html")
...
}
Same result.
I try fetch dir:
...
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))
...
Result:
Dir: %!(EXTRA string=/base/data/home/apps/tmp-LEIYJC/_ah) OK[/base/data/home/apps/tmp-LEIYJC/_ah/exe] |
Dirs:[] |
Ooops. What I done wrong?
UPD:
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
I put app.yaml to subdirectory, cause without that another problem: [https://groups.google.com/forum/#!topic/google-appengine-go/dNhqV6PBqVc
Folder structure:
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
...
Upvotes: 0
Views: 964
Reputation: 688
I found next solution.
I reorginize structure:
app/
static/
...
frontend/
views/
home/
*.html
user/
*.html
anotherfolder/
*.html
backend/
views/
main/
*.html
anotherfolder/
*.html
app.go
app.yaml
frontend/
controllers/
UserController.go
...
models/
UserModel.go
...
backend/
controllers/
MainController.go
...
models/
SomeModel.go
...
...
Change:
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
It's really strange ecision GAE. I can't put app.yaml to root directory for application because I got panic message for duplication import. And I can't put templates to root directory because that not under scope, only at directory parent to app.yaml
Upvotes: 2
Reputation: 1088
If I'm not mistaken all of your directories should live within the root directory where your app.yaml exists. So you would want something like this. Also, when you want your application to access a static file directory you need to add application_readable: true
to that directories definition. See the next example down. Hope this helps.
app/
app.go
app.yaml
static/
...
frontend/views/
home/
*.html
anotherfolder/
*.html
Example Directory Definition:
- url: /s
static_dir: s/
application_readable: true
Upvotes: 1