Cory LaNou
Mar 17 · 3 min read
#!/usr/bin/env bash

fmtcount=`git ls-files | grep '.go$' | xargs gofmt -l 2>&1 | wc -l`
if [ $fmtcount -gt 0 ]; then
echo "Some files aren't formatted, please run 'go fmt ./...' to format your source code before committing"
exit 1
fi

vetcount=`go vet ./... 2>&1 | wc -l`
if [ $vetcount -gt 0 ]; then
echo "Some files aren't passing vet heuristics, please run 'go vet ./...' to see the errors it flags and correct your source code before committing"
exit 1
fi
# from the root of your project:
curl -o .git/hooks/pre-commit https://gist.githubusercontent.com/corylanou/3639c901965922d5507ce4acf539de4a/raw/e535b525c408b5b145fed5d17c854c2a6dc90216/pre-commit
chmod +x .git/hooks/pre-commit
$ commit 'test'
Some files aren't formatted, please run 'go fmt ./...' to format your source code before committing

Cory LaNou

Written by

Cory LaNou a full stack technologist who has specialized in start-ups for the last 20 years. Cory enjoys mentoring budding technologists and entrepreneurs .

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade