首页 > 解决方案 > 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?

标签: gorefactoringgo-modules

解决方案


此功能在 GoLand 版本 2021.1 中引入。

Shift+F6您可以通过按下文件中的模块名称来调用重命名重构go.mod


推荐阅读