Last active
October 13, 2020 18:02
-
-
Save leizongmin/f8795cb9e514fbe695c07867e4a6b46d to your computer and use it in GitHub Desktop.
go-mini-build
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
#!/bin/sh | |
usage() { | |
echo "usage: go-mini-build <package-name> [output-path]" | |
} | |
file_size() { | |
echo $(ls -lh "$1" | awk '{print $5}') | |
} | |
if [ -z "$1" ]; then | |
usage | |
exit 1 | |
else | |
export PACKAGE="$1" | |
fi | |
if [ -z "$2" ]; then | |
export OUTPUT="out" | |
else | |
export OUTPUT="$2" | |
fi | |
export PREFIX="go-mini-build" | |
echo "$PREFIX> package:\t$PACKAGE" | |
echo "$PREFIX> output: \t$OUTPUT" | |
go build -v -ldflags "-s -w" -o $OUTPUT $PACKAGE && \ | |
echo "$PREFIX> original size:\t$(file_size $OUTPUT)" && \ | |
gzexe "$OUTPUT" && \ | |
rm -f "$OUTPUT~" && \ | |
echo "$PREFIX> final size:\t$(file_size $OUTPUT)" && \ | |
echo "$PREFIX> done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment