Last active
November 2, 2024 17:57
-
-
Save iamucil/7578dc7df7d72e1d78c8f5543db3fbcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go mod edit -module {NEW_MODULE_NAME} | |
-- rename all imported module | |
find . -type f -name '*.go' \ | |
-exec sed -i -e 's,{OLD_MODULE},{NEW_MODULE},g' {} \; |
For (unfortunate) Windows/Powershell users:
# Replace these values with appropriate ones
$NEW_MODULE_NAME = "NEW"
$OLD_MODULE = "OLD"
go mod edit -module $NEW_MODULE_NAME
# Rename all imported modules in .go files
Get-ChildItem -Path . -Filter '*.go' -Recurse | ForEach-Object {
$content = Get-Content -Path $_.FullName
$updatedContent = $content -replace $OLD_MODULE, $NEW_MODULE_NAME
$updatedContent | Set-Content -Path $filePath
}
For MACOS, Linux
#!/usr/bin/env sh
export CUR="github.com/..."
export NEW="github.com/..."
go mod edit -module ${NEW}
find . -type f -name '*.go' -exec perl -pi -e 's/$ENV{CUR}/$ENV{NEW}/g' {} \;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For OSX users