-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
accounts/abi/bind: stop using goimports in the binding generator #17768
Conversation
In projects with large GOPATHs, goimports can take a long time to run. goimports has also not been updated for Go 1.11 modules: golang/go#27287 golang/go#27865 golang/go#24661 Instead of using goimports to insert import statements, this commit generates imports directly in the Go template.
I’m very open to feedback here. Let me know what you think. I created this PR after running into two different pain points with
Note that I already have a reasonable workaround for (1), and (2) will eventually be patched upstream, so I don’t think this is critical to solve. But it seemed like a bit of a smell to me that this bit of code caused pain points twice in my project, so I decided to propose this change. Notable downsides to this approach include increased maintenance cost (needing to manage these hard-coded imports), and occasionally generating code that imports packages it does not need. The latter could be solved by adding logic to only insert imports when we know they are needed, though I suspect that would not be worth the increased complexity. I got the idea for doing imports this way from the Go protobuf implementation, which does a very similar thing: generator and example output. The code now also doesn’t go through gofmt, but I could add that back in. |
I'm very happy about this change. Please add gofmt and delete goimports from vendor/ to make this PR perfect :). |
goimports used to do this formatting. To keep the generated code in gofmt style, we now need to format it here ourselves.
bind.Bind now works in symlinked environments.
This package is no longer used.
Thanks for the review @fjl Anything I can do to help get this merged? I'm itching to try out Go 1.11 modules in my project :) |
In projects with large GOPATHs, goimports can take a long time to run.
goimports has also not been updated for Go 1.11 modules:
golang/go#27287
golang/go#27865
golang/go#24661
Instead of using goimports to insert import statements, this commit generates imports directly in the Go template.