Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
.PHONY: help lint test test-verbose test-coverage test-coverage-html test-clean
.PHONY: help lint test test-verbose test-coverage test-coverage-html test-clean install-pre-push-hook uninstall-pre-push-hook

help:
@echo "Available commands:"
@echo " help - Show this help message"
@echo " lint - Run golangci-lint on the codebase"
@echo " test - Run all tests"
@echo " test-verbose - Run all tests with verbose output"
@echo " test-coverage - Run all tests with coverage report"
@echo " test-coverage-html - Run all tests and generate HTML coverage report"
@echo " test-clean - Clean test cache and run tests"
@echo " help - Show this help message"
@echo " lint - Run golangci-lint on the codebase"
@echo " test - Run all tests"
@echo " test-verbose - Run all tests with verbose output"
@echo " test-coverage - Run all tests with coverage report"
@echo " test-coverage-html - Run all tests and generate HTML coverage report"
@echo " test-clean - Clean test cache and run tests"
@echo " make install-pre-push-hook - Install the pre-push git hook"
@echo " make uninstall-pre-push-hook - Uninstall the pre-push git hook"

lint:
golangci-lint run ./...
Expand All @@ -34,3 +36,15 @@ test-coverage-html:
test-clean:
@echo "Cleaning test cache and running tests..."
go clean -testcache && go test -v ./test/...

install-pre-push-hook:
@echo "Installing pre-push git hook..."
@mkdir -p .git/hooks
@cp scripts/git-pre-push.sh .git/hooks/pre-push
@chmod +x .git/hooks/pre-push
@echo "Pre-push hook installed successfully!"

uninstall-pre-push-hook:
@echo "Uninstalling pre-push git hook..."
@rm -f .git/hooks/pre-push
@echo "Pre-push hook uninstalled successfully!"
17 changes: 17 additions & 0 deletions scripts/git-pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

echo "Running pre-push checks..."

echo "\n=== Running linting ==="
if ! make lint; then
echo "❌ Linting failed! Please fix the issues before pushing."
exit 1
fi

echo "\n=== Running tests ==="
if ! make test; then
echo "❌ Tests failed! Please fix the test issues before pushing."
exit 1
fi

echo "\n✅ All checks passed! Pushing can continue...\n"
10 changes: 10 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ func GetAndParseFromContext[T any](ctx *gin.Context, key string) (T, error) {

return ezutil.Parse[T](asserted)
}

func WrapHandler(handler func(ctx *gin.Context) (int, string, any, error)) gin.HandlerFunc {
return func(ctx *gin.Context) {
if statusCode, message, response, err := handler(ctx); err != nil {
_ = ctx.Error(err)
} else {
ctx.JSON(statusCode, NewResponse(message).WithData(response))
}
}
}