# Define variables BIN_DIR := ./bin APP_NAME := safelineApi SRC_DIR := ./cmd/safelineApi VERSION := 1.0.0 BUILD_TIME := $(shell date +"%Y-%m-%dT%H:%M:%S") .DEFAULT_GOAL := build # Build task build: @echo "Building $(APP_NAME) version $(VERSION)..." mkdir -p $(BIN_DIR) go build -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)" -o $(BIN_DIR)/$(APP_NAME) $(SRC_DIR) # Run task run: @echo "Running $(APP_NAME)..." $(BIN_DIR)/$(APP_NAME) # Clean task clean: @echo "Cleaning up..." rm -rf $(BIN_DIR) # Test task test: @echo "Running tests..." go test ./... # Format code fmt: @echo "Formatting code..." go fmt ./... # Vet code vet: @echo "Vetting code..." go vet ./... # Install dependencies tidy: @echo "Tidying dependencies..." go mod tidy # Cross-platform build build-all: @echo "Building for all platforms..." GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/$(APP_NAME)-linux-amd64 $(SRC_DIR) GOOS=windows GOARCH=amd64 go build -o $(BIN_DIR)/$(APP_NAME)-windows-amd64.exe $(SRC_DIR) GOOS=darwin GOARCH=amd64 go build -o $(BIN_DIR)/$(APP_NAME)-darwin-amd64 $(SRC_DIR)