-
Notifications
You must be signed in to change notification settings - Fork 83
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
Support generating multiple variables (within same package). #23
Comments
Thanks for reporting this. This is a valid issue. It's also a known issue, but somehow I forgot to file it. So thanks for doing it. Yes, with the current setup, a single package can only have one instance of a vfsgen-generated file. That's because each file bundles support types (with methods) with fixed names, so as soon as you put two _vfsdata.go files together in same package, it's a name collision. I've thought a little about a way to resolve this, but couldn't find anything great so far. The thing is, this limitation (1 _vfsdata.go file per Go package) is usually not a problem. I usually end up composing my desired filesystem to contain multiple pieces using See some examples:
After starting to do that, I haven't run into this issue and completely forgot about it. That said, it would be good to resolve it and allow vfsgen to generate multiple files per single package, but only if it can be done in a way that's good, without negative compromises. Some ideas for how to resolve this issue:
|
God I love your union filesystem! I think with it this is not necessary either. |
Closing this since its not necessary. 👍 |
I feel like resolving this would still be nice, if we can find a great way of doing it. But I agree the need for it is low right now. I'm okay to keep this closed until there's a higher pressing need, but I'll still keep trying to come up with a great solution. |
This is exactly what I need :( |
@ababo, does the above solution of using the |
No since I use one FS for templates which should not be exposed outside, another one for statics. So I had to create two different packages. |
I see. Separate packages certainly works. If you happen to get an idea for how to make this possible in a good way (without compromising on the nice properties of the current solution), I'd be glad to hear it, but I don't have any ideas myself right now and I've thought about this quite a bit. |
Probably I don't understand the nature of the problem. Why not to generate code which will depend on your package (and there you can define all the shared types, e.g. file, dir, etc.)? |
Do you mean to factor out all the common types into a package (which currently generate an error as soon as you have two or more instances of them in same package), and have the generated code import that package? That would work, but it would lose the property of the current generated code being completely standalone. It'd kinda require you to vendor the said package, otherwise risk your generated code going out of sync with the package it imports. |
If you want to generate completely standalone package your tool can create two files: one for shared definitions, another - for compressed data. The first one will simply be rewritten each time user calls vfsgendev to add a new FS. |
@ababo That sounds like a fantastic idea (and pretty obvious in hindsight, but I couldn't think of it before)... Thank you. I'll give it a shot. |
👍 |
The goal is to resolve #23, to make it possible to use vfsgen multiple times in same package. Previously, that would cause an error because the same types would be defined in each generated file. The approach to solve that is to generate two files: - VFS data file - common type definitions file This avoids the multiple declaration issues in an efficient way. A downside is having 2 files as generated output, instead of one.
Seems to be OK. The only (minor) thing I would suggest is to shorten names of generated files. Why not to provide idiomatically laconic names, e.g. |
I was worried about naming collisions. But I suppose they should be rare enough, so I like your suggestion of short names. It's possible to provide custom filenames if one wants (unless they use Although I think it's nice to be able to spot generated files (that one can safely ignore when looking to edit code) from non-generated ones by looking at the filenames, which becomes harder when the filenames are that short and nice. |
Multiple calls to vfsgendev create all _vfsgen_dirInfo and _vfsgen_fs so its not possible to put multiple http.FileSystems into one package.
How to do this?
The text was updated successfully, but these errors were encountered: