Photo by Mark Duffel on Unsplash
Fixed: The file is not `goimports`-ed with ...
Obeying Golang rules will make you 1x engineer
If you have ever encountered the error below in your IDE, Go is reminding you to follow its rules. Go is quite strict about its rules, and sometimes it's best to say, Yes, my lord, as you wish.
Error: File is not
goimports
-ed with ...
To fix this problem, we have 2 solutions that I am aware of for now
- Execute the manual
goimports
command with the given file or project root directory as shown below. Ensure that you havegoimports
installed it on your system.
go install golang.org/x/tools/cmd/goimports@latest #install goimports
#for a single file
- goimports -w -local path/to/your/project/internal/services/service_multi.go
#for whole project
- goimports -w -local path/to/your/project ./...
2-If you use Goland/IntelliJIDEA, you can automate this setting from the IDE's menu. Navigate to Settings/Editor/Code Style/Go
and adjust Sorting type
to goimports
. After making this adjustment, your IDE will take care of sorting import statements, allowing you to concentrate on your actual tasks.
Until the next error, stay human, and resist AI!