-
Notifications
You must be signed in to change notification settings - Fork 415
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
Package is a program, not an importable package #1
Comments
The issue is that bootstrapping code needs to import the package to do reflection on required structs and this doesn't quite work with main package. I'll look into the options to make this case work. As for gofmt, does this cause any trouble? The only case I can think of is when you edit it and gofmt will be run automatically, but it's generally a bad practice to manually edit an autogenerated file. |
Ah, got it. Yes, it would be bad to edit a generated file. For that reason I think it is worth writing a properly |
And it will play nicely for those who use pre-commit git hooks with gofmt too. |
That's perfectly reasonable. I just wanted a use-case to be sure what scenario I am fixing. I've added 'gofmt -w' invocation, see #3. Haven't gotten to fixing the main package yet, though. |
you could avoid the whole issue likely by using the AST packages instead of creating a executable and using reflection. would also make it possible to regenerate the json methods when you remove a field from a structure without having to delete the easyjson file. |
@james-lawrence Using AST would also be quite fast to generate. That's exactly what I tried doing at first. Unfortunately the code turned out to be more complex than I was willing to support. Maybe I was just using it the wrong way. On the issue: it seems to be a rather rare scenario, so I didn't get to it yet. I'll have some time to experiment with it over this weekend, looks like it won't be too hard to fix. |
I'm having this problem too, on a small enough package that I don't want to split the pair of structs I need to play with to another package. Any news ? |
Any news on the AST parser approach? The use case is as mentioned above by @elwinar - sometimes it's convenient to keep your structs in same source tree and not split into a separate package just because of EasyJSON. |
This should probably be noted in the Readme (for now?). It is a limitation of the library and will confuse people who try to use the library after reading through it. |
@TheSilvus I'm just saying that it would be nice to be able to parse local files (as opposed to having to reference external compile-able packages), which means taking the AST approach to generating metadata. I know this was in the plans at some point, but no actual progress. Are you saying that the plans have changed, and this definitely won't be implemented? |
@kmansoft Probably didn't explain myself well, sorry. I've only used this library and don't know about its internals, but wanted to suggest this limitation (at least until it's implemented) to be notes in the readme. |
Fix of this was offered in #236 |
Fails when running against this file...
I've created package
foo
, and have the following filemain.go
Output
A file called
main_easyjson.go
with the following content is createdgofmt
'ed.The text was updated successfully, but these errors were encountered: