Skip to content

Instantly share code, notes, and snippets.

@ysugimoto
Created September 14, 2020 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysugimoto/8e63d6ad569c2ba2dcb5631ec26a2dc3 to your computer and use it in GitHub Desktop.
Save ysugimoto/8e63d6ad569c2ba2dcb5631ec26a2dc3 to your computer and use it in GitHub Desktop.
Ensure you are not using replaced package in go.mod.
#!/bin/bash
findup () {
CWD=$1
while [ "$CWD" != "/" ]; do
if [ -f "$CWD/go.mod" ]; then
echo "$CWD/go.mod"
return 0
fi
CWD=$(dirname $CWD)
done
echo "Could not find go.mod in your directry tree"
exit 1
}
MODFILE=$(findup $PWD)
if [ $? = "0" ]; then
FOUND=$(cat $MODFILE | grep -e "^replace")
if [ "$FOUND" != "" ]; then
echo "Your Go project is using replaced package!"
echo "Make sure you are using package which is placed in exteranal host."
exit 1
fi
exit 0
else
echo $MODFILE
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment