Open baconalot opened 10 years ago
There is a go package called goimports (https://godoc.org/code.google.com/p/go.tools/cmd/goimports) that does what you are wanting.
It basically replaces the normal gofmt command, with one that does import magic.
To use in goclipse:
1) install goimports:
go get code.google.com/p/go.tools/cmd/goimports
2) in eclipse goto: Preferences -> Go -> Go Formatter and set it to be the path of the goimports bin
This will fix all imports when you format. If you combine this with #67, then imports will be automatically fixed on save.
Brilliant, works like a charm. Maybe an idea to update the doc to mention this?
The new command to get goimports is:
go get golang.org/x/tools/cmd/goimports
I saw some guys that were working with go in vi, that had a nifty feature that constructed the right imports on save. So when they put in the first fmt.Println("") it would automatically add "fmt" to the imports, and when a import was not needed anymore it would be removed. Cant remember what script did that, but would be nice to have.