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

multiple static paths #44

Open
jrhare opened this issue Apr 20, 2018 · 1 comment
Open

multiple static paths #44

jrhare opened this issue Apr 20, 2018 · 1 comment

Comments

@jrhare
Copy link

jrhare commented Apr 20, 2018

Have /static path with web content I'd like to serve and /templates for server consumption. Tried the following but got compile error on generated code (variable redefined or something like that):

var fs1 http.FileSystem = http.Dir("static")
vfsgen.Generate(fs1, vfsgen.Options{})

var fs2 http.FileSystem = http.Dir("templates")
vfsgen.Generate(fs2, vfsgen.Options{})

This is an enhancement request to support multiple virtual file system's in same app.

Note: because templates are for internal server consumption, I'm not asking to support multiple static paths in the same VFS (although that would be nice as well but not what I need right now).

@dmitshur
Copy link
Member

dmitshur commented Apr 20, 2018

Have you seen package github.com/shurcooL/httpfs/union?

For example, see it being used here.

You could do something like this:

// Assets contains assets for some project.
var Assets = union.New(map[string]http.FileSystem{
	"/static":    http.Dir("static"),
	"/templates": http.Dir("templates"),
	// plus anything else
})

Then serve static content with something like:

assetsFileServer := httpgzip.FileServer(assets.Assets, httpgzip.FileServerOptions{})
http.Handle("/static/", assetsFileServer)

For templates, you can use package github.com/shurcooL/httpfs/html/vfstemplate.

This is an enhancement request to support multiple virtual file system's in same app.

There's an issue tracking that, it's issue #23.

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