Skip to content

Instantly share code, notes, and snippets.

@iamucil
Last active April 24, 2024 16:33
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save iamucil/7578dc7df7d72e1d78c8f5543db3fbcc to your computer and use it in GitHub Desktop.
Save iamucil/7578dc7df7d72e1d78c8f5543db3fbcc to your computer and use it in GitHub Desktop.
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' {} \;
@stephenafamo
Copy link

For OSX users

find . -type f -name '*.go' \
  -exec sed -i '' -e 's/{OLD_MODULE}/{NEW_MODULE}/g' {} \;

@sinux-l5d
Copy link

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment