Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embeded Static file support on golang 1.16 standard Example #25

Open
golfapipol opened this issue May 4, 2021 · 1 comment
Open

Embeded Static file support on golang 1.16 standard Example #25

golfapipol opened this issue May 4, 2021 · 1 comment

Comments

@golfapipol
Copy link

I see issue #9 that you have support on go.rice
#9
do you have plan to support go embeded or do you have example to do it?
https://golang.org/pkg/embed/

@terrbear
Copy link

terrbear commented Jul 9, 2021

If you've a file layout with like, ui/index.html and ui/whatever.html, you can do this:

//go:embed ui/*
var ui embed.FS

func embeddedFH(config goview.Config, tmpl string) (string, error) {
	path := filepath.Join(config.Root, tmpl)
	bytes, err := ui.ReadFile(path + config.Extension)
	return string(bytes), err
}

func main() {
	//new template engine
	gv := ginview.New(
		goview.Config{
			Root:         "ui",
			Extension:    ".html",
		},
	)
	gv.ViewEngine.SetFileHandler(embeddedFH)
	router.HTMLRender = gv
}

And it'll render from your embedded assets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants