Skip to content

Instantly share code, notes, and snippets.

@flamendless
Created September 19, 2024 09:20
Show Gist options
  • Save flamendless/b6d21a1feb9332ab28c4a0a232f7bd5b to your computer and use it in GitHub Desktop.
Save flamendless/b6d21a1feb9332ab28c4a0a232f7bd5b to your computer and use it in GitHub Desktop.
Script for Go
#!/usr/bin/env bash
# script for Linux (WSL-compatible) dev workflow
# Brandon Blanker Lim-it @flamendless
set -euf -o pipefail
source .env
PROJ=""
GOOS="linux"
sc() {
go mod tidy
go vet ./...
prealloc ./...
smrcptr ./...
goimports -local "${PROJ}" -w .
}
benchmark() {
go test -bench=. -benchmem ./...
}
benchmarkhigh() {
go test -bench=. -benchmem -count=5 ./...
}
testall() {
go test -test.v -cover -shuffle=on -race ./...
}
prof() {
go test -cpuprofile cpu.prof -memprofile mem.prof -benchmem -bench=. ./"${2}"
go tool pprof -http=localhost:3031 "${3}".prof
}
testlocal() {
go run .
}
if [ "$#" -eq 0 ]; then
echo "First use: chmod +x ${0}"
echo "Usage: ${0}"
echo "Commands:"
echo " sc"
echo " benchmark"
echo " benchmarkhigh"
echo " prof"
echo " testall"
echo " testlocal"
else
time "$1" "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment