Created
April 9, 2024 18:47
-
-
Save FelicianoTech/b5f72b5b1606560033422e452bfc0dda to your computer and use it in GitHub Desktop.
A small script to rename a Go module and its import statements through out the source code.
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
#!/usr/bin/env bash | |
# Run this script as: | |
# ./rename-go-module.sh example.com/old/module example.com/new-module | |
go mod edit -module "${2}" | |
find . -type f -name '*.go' -exec sed -i -e "s,\"${1}/,\"${2}/,g" {} \; | |
find . -type f -name '*.go' -exec sed -i -e "s,\"${1}\",\"${2}\",g" {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by: https://gist.github.com/iamucil/7578dc7df7d72e1d78c8f5543db3fbcc
Blog post with explanation: https://www.feliciano.tech/blog/3-ways-to-rename-a-go-module/