Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Gorice example not working in development mode #9

Closed
gihnius opened this issue May 9, 2018 · 3 comments
Closed

Gorice example not working in development mode #9

gihnius opened this issue May 9, 2018 · 3 comments

Comments

@gihnius
Copy link

gihnius commented May 9, 2018

in example gorice:

remove generated rice-box.go (considered as development mode)
go build
./gorice

get panic when acess the http index:

could not locate box "views"

happends where to call gorice.New:

gorice.New(rice.MustFindBox("views"))

alt it works when as static assets: r.StaticFS("/assets", rice.MustFindBox("views").HTTPBox())

@foolin
Copy link
Owner

foolin commented May 9, 2018

@gihnius
Copy link
Author

gihnius commented May 9, 2018

@foolin I fixed this by preventing realtime(dynamic) FindBox call:

diff --git a/supports/gorice/gorice.go b/supports/gorice/gorice.go
index bc3a11d..b24843f 100644
--- a/supports/gorice/gorice.go
+++ b/supports/gorice/gorice.go
@@ -19,18 +19,13 @@ Important!!! The viewsRootBox's name and config.Root must be consistent.
 func NewWithConfig(viewsRootBox *rice.Box, config gintemplate.TemplateConfig) *gintemplate.TemplateEngine {
        config.Root = viewsRootBox.Name()
        engine := gintemplate.New(config)
-       engine.SetFileHandler(GoRiceFileHandler())
+       engine.SetFileHandler(GoRiceFileHandler(viewsRootBox))
        return engine
 }

-func GoRiceFileHandler() gintemplate.FileHandler {
+func GoRiceFileHandler(viewsRootBox *rice.Box) gintemplate.FileHandler {
        return func(config gintemplate.TemplateConfig, tplFile string) (content string, err error) {
-               // find a rice.Box
-               templateBox, err := rice.FindBox(config.Root)
-               if err != nil {
-                       return "", err
-               }
                // get file contents as string
-               return templateBox.String(tplFile + config.Extension)
+               return viewsRootBox.String(tplFile + config.Extension)
        }
 }

@gihnius gihnius changed the title Example not working Gorice example not working in development mode May 9, 2018
@foolin
Copy link
Owner

foolin commented May 15, 2018

The code has fixed, Thank you!

@foolin foolin closed this as completed May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants