Skip to content

Instantly share code, notes, and snippets.

@felicianotech
Created April 9, 2024 18:47
Show Gist options
  • Save felicianotech/b5f72b5b1606560033422e452bfc0dda to your computer and use it in GitHub Desktop.
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.
#!/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" {} \;
@felicianotech
Copy link
Author

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