Skip to content

Instantly share code, notes, and snippets.

@jmhungdev
Last active March 17, 2023 06:54
Show Gist options
  • Save jmhungdev/72dfd0899f77edf16140bd83dadaa623 to your computer and use it in GitHub Desktop.
Save jmhungdev/72dfd0899f77edf16140bd83dadaa623 to your computer and use it in GitHub Desktop.
rename go module and update import paths
#!/bin/bash
OLD_MODULE_NAME=jmhungdev/go-example
NEW_MODULE_NAME=jmhundev/go-lessons
# replace module name in go.mod
go mod edit -module $NEW_MODULE_NAME
# find all .go files in current dir and sub dirs
# for each file replace old module name with the new one in place
find . -type f -name '*.go' \
-exec sed -i '' -e 's/$OLD_MODULE_NAME/$NEW_MODULE_NAME/g' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment