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

Add ForceAllTypes to Options #63

Closed
wants to merge 1 commit into from
Closed

Add ForceAllTypes to Options #63

wants to merge 1 commit into from

Conversation

kenshaw
Copy link

@kenshaw kenshaw commented Dec 1, 2018

Adds a ForceAllTypes member to Options, forcing the generation of both
the vfsgen۰CompressedFileInfo and vfsgen۰FileInfo types. Useful for
other using packages that need to ensure that both types are present.

Adds a `ForceAllTypes` member to Options, forcing the generation of both
the `vfsgen۰CompressedFileInfo` and `vfsgen۰FileInfo` types. Useful for
other using packages that need to ensure that both types are present.
@kenshaw
Copy link
Author

kenshaw commented Dec 1, 2018

Appreciate the work you've done with this package!

I am making use of this package in a different code generator that makes use of this package for binary packing of assets. For my specific use case, I am generating additional Go files (to sit in same package as code generated by vfsgen), and need to do a type switch on the vfsgen۰CompressedFileInfo and vfsgen۰FileInfo types (retrieved through vfsutil.Walk).

This change is needed in order to correctly build a different type that also satisfies the http.FileSystem interface. Without this change, I'm forced to make a very horrible hack: basically, a small file and a compressible file has to be also be added to the file set when using vfsgen.Generate directly. Since these files end up in the final code, they are accessible if someone knows the magic paths.

This PR solves this by adding a ForceAllTypes bool to the Options type, and modifies the templates to correctly recognize that option. It was purposefully written in way to be backwards compatible, and has been extensively tested in production.

@dmitshur
Copy link
Member

dmitshur commented Dec 2, 2018

Hi @kenshaw,

Thank you for the PR and for the detailed rationale for why you want this.

Added a thinking label because I'd like to take some time before making a decision here, but let me tell you my current thinking.

I have some concerns about adding a feature strictly used by an external tool, since it's harder for me to maintain it and know if it breaks. However, I think your use case is reasonable and I'd like to make it possible for you to achieve it.

I have an alternative idea for how we can support this and I'd like to get your thoughts on this. It's something I've been considering for a while, and I think I might be getting closer to deciding to do it. The idea is to make a change to vfsgen so that instead of embedding all those vfsgen۰CompressedFileInfo, vfsgen۰FileInfo, etc., internal types in the generated code as unexported identifiers, but rather factor those out into a package and have the generated code import it.

It should solve your use case since your code could just import the same package and use its types.

It would be simplify a bunch of logic around which packages need to be imported in the generate code, and make it possible to resolve issue #23 (support generating multiple variables within same package). It should be slightly more efficient in situations where multiple vfsgen-generated filesystems are used (in different packages), since the common types would be reused rather than repeated.

vfsgen currently generates a single self-contained .go file without any 3rd party packages, which has nice properties. However, with Go modules happening, it should be more viable confidently rely on a fixed version of a 3rd party package, so it could be more acceptable to generate code that does that.

I'm going to file a separate issue to discuss that decision in more depth, but I wanted to ask how you'd feel about it here first. Thanks!

@kenshaw
Copy link
Author

kenshaw commented Dec 2, 2018

To be honest, it doesn't matter much either way. However, there is something nice about having a fully contained package, though. "A little copying is better than a little dependency..."

@kenshaw
Copy link
Author

kenshaw commented Dec 2, 2018

I would suggest: it works now well on its own -- no hard requirement to refactor it.

@kenshaw
Copy link
Author

kenshaw commented Dec 15, 2018

Have you made a decision on this? Thanks!

@kenshaw
Copy link
Author

kenshaw commented Mar 3, 2019

I'm assuming at this point this isn't likely to be merged?

@kenshaw
Copy link
Author

kenshaw commented Apr 5, 2019

Any further thinking done?

@dmitshur
Copy link
Member

Sorry about the delays.

I am leaning towards not merging this PR as is because of the increased difficulty of maintenance, and I don't have the bandwidth to spend on this now. However, I do want to aim to resolve the underlying problem in a module-based v2 API (as part of resolving #23).

I suggest using a fork with this ForceAllTypes functionality if you'd like to use it until that happens. Thank you.

@dmitshur dmitshur closed this Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants