Last active
April 10, 2023 00:29
-
-
Save hailelagi/c5d596e2b4379c529337b16b147866b5 to your computer and use it in GitHub Desktop.
scaffold.sh
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
# for ~/.zshrc | |
# usage `go-new package_name` binary scaffold OR | |
# `go-new package_name --lib` library scaffold | |
goScaffold () | |
{ | |
mkdir -p -- "$1" && | |
cd -P -- "$1" && | |
touch -- "$1.go" && | |
touch -- "$1_test.go" | |
if [[ $2 == 'lib' || $2 == "--lib" ]] then | |
echo "package $1" > "$1.go" && | |
echo "package $1\n\nimport \"testing\"" > "$1_test.go" | |
else | |
echo "package main\n\nfunc main(){\n}\n" > "$1.go" && | |
echo "package main\n\nimport \"testing\" " > "$1_test.go" && | |
go mod init $1 | |
fi | |
} | |
alias "go-new"="goScaffold" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment