I have a Go module named mymodule
, and I'd like to rename it into github.com/hylowaker/awesome-module
Using command go mod edit -module github.com/hylowaker/awesome-module
only changes module name in go.mod
file, leaving go sources unchanged. I tried Refactor feature in GoLand IDE, but GoLand does not allow renaming with slash(/
) characters.
So I had to find and replace every import "mymodule/..."
into import "github.com/hylowaker/awesome-module/...
from my source files.
Is there a better way to refactor them?
Press Shift+F6 or from the main menu, select Refactor | Rename.
Go modules commonly consist of one project or library and contain a collection of Go packages that are then released together. Go modules solve many problems with GOPATH , the original system, by allowing users to put their project code in their chosen directory and specify versions of dependencies for each module.
This feature is introduced in GoLand version 2021.1.
You can invoke the Rename refactoring by pressing Shift+F6
on the module name in the go.mod
file.
In GoLand just press Ctrl+Shift+R and execute "Replace in Path"
It is safe to perform that in entire project since you only need to change go.mod file and all import clauses
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With