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 file packages #56

Closed
titpetric opened this issue Nov 12, 2018 · 6 comments
Closed

Multiple static file packages #56

titpetric opened this issue Nov 12, 2018 · 6 comments

Comments

@titpetric
Copy link

titpetric commented Nov 12, 2018

I'd like to produce two (or more) different statik fs's in different import paths. Due to relying on init() and no public API from the package, it's impossible to use both filesystems at the same time; concurrent access is also impossible as fs.Register is package-scoped.

I'd propose modifying the API:

fs.New would take zipDatas ...string and fallback on whatever was put in fs.Register (backwards compatible),
The generated filesystem package could add Data() string for this purpose in addition to keeping init() behaviour.

@pkieltyka
Copy link

@titpetric here is a fork'd version with the fix.. https://github.com/goware/statik as well as a new -a flag to pass pkg-level variable name to reference the asset. And fs.New() which accept the zipdata string

@dolmen
Copy link
Contributor

dolmen commented Mar 22, 2019

This request would change this project from a very minimalist solution to a more general one, but less lightweight.

If you need something less minimalist, just fork the project to build something else.

@dolmen
Copy link
Contributor

dolmen commented Mar 22, 2019

Well, in fact, you can already do that with the existing code. The trick is to import the statik packages in separate packages and to call fs.New() before another package registers data again. To achieve that, fs.New() has to be called at init time (in an init function or in a package-scoped variable declaration).

Example:

package pkg1

import (
    "github.com/rakyll/statik/fs"
    _ "pkg1/statik"
)

var FS = fs.New()
package pkg2

import (
    "github.com/rakyll/statik/fs"
    _ "pkg2/statik"
)

var FS = fs.New()

You can now use both pkg1.FS and pkg2.FS.

Note: this is garanteed to work because the Go language specification garantees that "Package initialization—variable initialization and the invocation of init functions—happens in a single goroutine, sequentially, one package at a time."

@titpetric
Copy link
Author

@pkieltyka thanks, i like that you moved away from init(). Going to migrate to your fork, eventually :)

Closing this issue as I don't think my PR is a good way forward. Moving away from init() will be a breaking change either way, and it's not up to me.

@titpetric
Copy link
Author

@pkieltyka p.s. would be nice if you'd generate statik.go and not static.go by default ;)

@aitva
Copy link

aitva commented Oct 17, 2019

Hi! I just hit the same problem. I have two directories in two package and I was very surprise to discover that they are on the same Filesystem. I love the minimalism of statik but this was unexpected.

This issue was closed.
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

4 participants