gorefactoringgo-modules

How do I refactor module name in Go?


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?


Solution

  • 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.