style: Apply go fmt to go code (#2046)

~I will add pre-commit hook later if I find a good one~

Found a nice repo, but it is no longer maintained:
https://github.com/dnephin/pre-commit-golang
So, I implemented the check as a local hook.
This commit is contained in:
Ayaz Salikhov
2025-04-28 16:04:50 +01:00
committed by GitHub
parent bebc683ba2
commit 424af5dfe0
6 changed files with 75 additions and 52 deletions

14
pre-commit-hooks/run-go-fmt.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
#
# Capture and print stdout, since gofmt doesn't use proper exit codes
#
set -e -o pipefail
if ! command -v gofmt &> /dev/null ; then
echo "gofmt not installed or available in the PATH" >&2
exit 1
fi
output="$(gofmt -l -w "$@")"
echo "$output"
[[ -z "$output" ]]