#!/usr/bin/env nu # Update buf dependencies buf-deps: buf dep update # Generate protobuf files proto: buf-deps buf generate # Build the server binary build: proto go build -o bin/server cmd/server/main.go # Run the server run: build ./bin/server # Clean build artifacts clean: rm -rf bin/ rm -rf proto/**/*.pb.go rm -rf proto/**/*.pb.gw.go rm -rf docs/ # Run tests test: go test ./... # Run linter lint: golangci-lint run # Install required tools and dependencies install-deps: @echo "Installing buf..." @if ! command -v buf >/dev/null 2>&1; then \ mkdir -p ~/.local/bin && \ curl -sSL "https://github.com/bufbuild/buf/releases/latest/download/buf-$(uname -s)-$(uname -m)" -o "$HOME/.local/bin/buf" && \ chmod +x "$HOME/.local/bin/buf"; \ echo "buf installed to ~/.local/bin/buf"; \ echo "Make sure ~/.local/bin is in your PATH"; \ else \ echo "buf already installed"; \ fi @echo "Installing protoc plugins..." go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest # Download and tidy dependencies deps: go mod download go mod tidy # Development workflow dev: deps proto run # Docker commands docker-build: docker build -t grpc-gateway-template:latest . docker-run: docker run --rm -p 8080:8080 -p 8090:8090 grpc-gateway-template:latest docker-push registry="": @if [ -z "{{registry}}" ]; then echo "Usage: just docker-push registry="; exit 1; fi docker tag grpc-gateway-template:latest {{registry}}/grpc-gateway-template:latest docker push {{registry}}/grpc-gateway-template:latest # Testing commands test-coverage: go test -coverprofile=coverage.out ./... go tool cover -html=coverage.out -o coverage.html test-integration: go test -tags=integration ./tests/... # Formatting and linting format: go fmt ./... goimports -w . # Health check command health: @curl -f http://localhost:8090/health || echo "Service not healthy" # Generate and serve API documentation docs: proto @echo "OpenAPI documentation generated in docs/" @if command -v python3 >/dev/null 2>&1; then \ echo "Serving docs at http://localhost:8080/docs"; \ cd docs && python3 -m http.server 8080; \ else \ echo "Install Python 3 to serve docs locally"; \ fi # Development with hot reload (requires air) dev-watch: @if ! command -v air >/dev/null 2>&1; then \ echo "Installing air for hot reload..."; \ go install github.com/cosmtrek/air@latest; \ fi air