# Hyperledger Fabric Asset Transfer API Makefile .PHONY: help build run test clean swagger docker-build docker-run lint fmt vet tidy env-setup # Default target help: ## Show this help message @echo 'Usage: make [target]' @echo '' @echo 'Targets:' @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST) # Setup environment configuration env-setup: ## Setup environment configuration files @echo "Setting up environment configuration..." @if [ ! -f config.env ]; then \ echo "Creating config.env from example..."; \ cp config.env.example config.env; \ echo "Please edit config.env with your specific configuration"; \ else \ echo "config.env already exists"; \ fi # Build the application build: ## Build the application binary @echo "Building application..." go build -o bin/asset-transfer-api cmd/server/main.go # Run the application run: ## Run the application @echo "Running application..." go run cmd/server/main.go # Run the application in development mode run-dev: ## Run the application in development mode @echo "Running application in development mode..." ENVIRONMENT=development go run cmd/server/main.go # Run the application in production mode run-prod: ## Run the application in production mode @echo "Running application in production mode..." ENVIRONMENT=production LOG_FORMAT=json go run cmd/server/main.go # Run tests test: ## Run tests @echo "Running tests..." go test -v ./... # Run tests with coverage test-coverage: ## Run tests with coverage @echo "Running tests with coverage..." go test -v -coverprofile=coverage.out ./... go tool cover -html=coverage.out -o coverage.html # Clean build artifacts clean: ## Clean build artifacts @echo "Cleaning..." rm -rf bin/ rm -f coverage.out coverage.html # Generate swagger documentation swagger: ## Generate swagger documentation @echo "Generating swagger documentation..." swag init -g cmd/server/main.go -o docs # Build docker image docker-build: ## Build docker image @echo "Building docker image..." docker build -t spiderman . # Run docker container docker-run: ## Run docker container @echo "Running docker container..." docker run -p 8080:8080 spiderman # Run docker container in development mode docker-run-dev: ## Run docker container in development mode @echo "Running docker container in development mode..." docker run -p 8080:8080 -e ENVIRONMENT=development spiderman # Run linting lint: ## Run golangci-lint @echo "Running linter..." golangci-lint run # Format code fmt: ## Format Go code @echo "Formatting code..." go fmt ./... # Run go vet vet: ## Run go vet @echo "Running go vet..." go vet ./... # Tidy dependencies tidy: ## Tidy go modules @echo "Tidying dependencies..." go mod tidy # Development setup dev-setup: env-setup deps ## Setup development environment @echo "Setting up development environment..." go mod download go install github.com/swaggo/swag/cmd/swag@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest @echo "Development environment setup complete!" @echo "" @echo "Next steps:" @echo " 1. Edit config.env with your Fabric network configuration" @echo " 2. Run 'make run-dev' to start in development mode" @echo " 3. Visit http://localhost:8080/swagger/ for API documentation" # Check code quality check: fmt vet lint test ## Run all checks (format, vet, lint, test) # Install dependencies deps: ## Download dependencies @echo "Downloading dependencies..." go mod download go mod verify # Show current configuration show-config: ## Show current configuration from environment @echo "Current Configuration:" @echo "PORT: $(shell echo $${PORT:-8080})" @echo "ENVIRONMENT: $(shell echo $${ENVIRONMENT:-development})" @echo "LOG_LEVEL: $(shell echo $${LOG_LEVEL:-info})" @echo "LOG_FORMAT: $(shell echo $${LOG_FORMAT:-text})" @echo "CHANNEL_NAME: $(shell echo $${CHANNEL_NAME:-mychannel})" @echo "CHAINCODE_NAME: $(shell echo $${CHAINCODE_NAME:-basic})"