Skip to content

Instantly share code, notes, and snippets.

@hailelagi
Last active April 10, 2023 00:29
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 hailelagi/c5d596e2b4379c529337b16b147866b5 to your computer and use it in GitHub Desktop.
Save hailelagi/c5d596e2b4379c529337b16b147866b5 to your computer and use it in GitHub Desktop.
scaffold.sh
# 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