Skip to content

Commit 636df36

Browse files
committed
added web http
0 parents  commit 636df36

File tree

5 files changed

+1214
-0
lines changed

5 files changed

+1214
-0
lines changed

Makefile

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Makefile for Web HTTP Exec
2+
3+
# Variables
4+
BINARY_NAME=webhttpexec
5+
BUILD_DIR=build
6+
MAIN_FILE=main.go
7+
PORT?=8080
8+
9+
# Go related variables
10+
GOCMD=go
11+
GOBUILD=$(GOCMD) build
12+
GOCLEAN=$(GOCMD) clean
13+
GOTEST=$(GOCMD) test
14+
GOGET=$(GOCMD) get
15+
GOMOD=$(GOCMD) mod
16+
BINARY_UNIX=$(BINARY_NAME)_unix
17+
18+
# Build flags
19+
LDFLAGS=-ldflags "-X main.Version=$(shell git describe --tags --always --dirty 2>/dev/null || echo 'dev')"
20+
21+
# Default target
22+
.DEFAULT_GOAL := help
23+
24+
# Help target
25+
.PHONY: help
26+
help: ## Show this help message
27+
@echo 'Usage: make [target]'
28+
@echo ''
29+
@echo 'Targets:'
30+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
31+
32+
# Build targets
33+
.PHONY: build
34+
build: ## Build the application
35+
@echo "Building $(BINARY_NAME)..."
36+
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_FILE)
37+
38+
.PHONY: build-linux
39+
build-linux: ## Build the application for Linux
40+
@echo "Building $(BINARY_NAME) for Linux..."
41+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_UNIX) $(MAIN_FILE)
42+
43+
.PHONY: build-darwin
44+
build-darwin: ## Build the application for macOS
45+
@echo "Building $(BINARY_NAME) for macOS..."
46+
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)_darwin $(MAIN_FILE)
47+
48+
.PHONY: build-windows
49+
build-windows: ## Build the application for Windows
50+
@echo "Building $(BINARY_NAME) for Windows..."
51+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME).exe $(MAIN_FILE)
52+
53+
.PHONY: build-all
54+
build-all: build build-linux build-darwin build-windows ## Build for all platforms
55+
56+
# Run targets
57+
.PHONY: run
58+
run: ## Run the application
59+
@echo "Running $(BINARY_NAME) on port $(PORT)..."
60+
PORT=$(PORT) $(GOCMD) run $(MAIN_FILE)
61+
62+
.PHONY: run-build
63+
run-build: build ## Build and run the application
64+
@echo "Running $(BINARY_NAME) on port $(PORT)..."
65+
PORT=$(PORT) ./$(BUILD_DIR)/$(BINARY_NAME)
66+
67+
# Development targets
68+
.PHONY: dev
69+
dev: ## Run in development mode with hot reload (requires air)
70+
@if command -v air > /dev/null; then \
71+
echo "Running with air for hot reload..."; \
72+
air; \
73+
else \
74+
echo "Air not found. Installing air..."; \
75+
go install github.com/cosmtrek/air@latest; \
76+
air; \
77+
fi
78+
79+
.PHONY: install-air
80+
install-air: ## Install air for hot reload development
81+
@echo "Installing air..."
82+
go install github.com/cosmtrek/air@latest
83+
84+
# Test targets
85+
.PHONY: test
86+
test: ## Run tests
87+
@echo "Running tests..."
88+
$(GOTEST) -v ./...
89+
90+
.PHONY: test-coverage
91+
test-coverage: ## Run tests with coverage
92+
@echo "Running tests with coverage..."
93+
$(GOTEST) -v -coverprofile=coverage.out ./...
94+
$(GOCMD) tool cover -html=coverage.out -o coverage.html
95+
@echo "Coverage report generated: coverage.html"
96+
97+
.PHONY: test-bench
98+
test-bench: ## Run benchmark tests
99+
@echo "Running benchmark tests..."
100+
$(GOTEST) -bench=. ./...
101+
102+
# Dependency management
103+
.PHONY: deps
104+
deps: ## Download dependencies
105+
@echo "Downloading dependencies..."
106+
$(GOGET) -v -t -d ./...
107+
108+
.PHONY: deps-update
109+
deps-update: ## Update dependencies
110+
@echo "Updating dependencies..."
111+
$(GOGET) -u ./...
112+
$(GOMOD) tidy
113+
114+
.PHONY: deps-clean
115+
deps-clean: ## Clean module cache
116+
@echo "Cleaning module cache..."
117+
$(GOCLEAN) -modcache
118+
119+
# Code quality targets
120+
.PHONY: fmt
121+
fmt: ## Format code
122+
@echo "Formatting code..."
123+
$(GOCMD) fmt ./...
124+
125+
.PHONY: vet
126+
vet: ## Vet code
127+
@echo "Vetting code..."
128+
$(GOCMD) vet ./...
129+
130+
.PHONY: lint
131+
lint: ## Run linter (requires golangci-lint)
132+
@if command -v golangci-lint > /dev/null; then \
133+
echo "Running linter..."; \
134+
golangci-lint run; \
135+
else \
136+
echo "golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
137+
fi
138+
139+
.PHONY: install-lint
140+
install-lint: ## Install golangci-lint
141+
@echo "Installing golangci-lint..."
142+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
143+
144+
# Clean targets
145+
.PHONY: clean
146+
clean: ## Clean build artifacts
147+
@echo "Cleaning build artifacts..."
148+
$(GOCLEAN)
149+
rm -rf $(BUILD_DIR)
150+
rm -f coverage.out coverage.html
151+
152+
.PHONY: clean-all
153+
clean-all: clean deps-clean ## Clean everything including dependencies
154+
155+
# Install targets
156+
.PHONY: install
157+
install: ## Install the application
158+
@echo "Installing $(BINARY_NAME)..."
159+
$(GOBUILD) $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY_NAME) $(MAIN_FILE)
160+
161+
# Docker targets
162+
.PHONY: docker-build
163+
docker-build: ## Build Docker image
164+
@echo "Building Docker image..."
165+
docker build -t $(BINARY_NAME) .
166+
167+
.PHONY: docker-run
168+
docker-run: ## Run Docker container
169+
@echo "Running Docker container..."
170+
docker run -p $(PORT):8080 $(BINARY_NAME)
171+
172+
.PHONY: docker-clean
173+
docker-clean: ## Clean Docker images
174+
@echo "Cleaning Docker images..."
175+
docker rmi $(BINARY_NAME) 2>/dev/null || true
176+
177+
# Release targets
178+
.PHONY: release
179+
release: clean build-all ## Build release binaries for all platforms
180+
@echo "Release binaries created in $(BUILD_DIR)/"
181+
182+
.PHONY: release-linux
183+
release-linux: clean build-linux ## Build release binary for Linux
184+
@echo "Linux binary created: $(BUILD_DIR)/$(BINARY_UNIX)"
185+
186+
# Utility targets
187+
.PHONY: check
188+
check: fmt vet test ## Run code checks (fmt, vet, test)
189+
190+
.PHONY: pre-commit
191+
pre-commit: fmt vet lint test ## Run all pre-commit checks
192+
193+
.PHONY: setup
194+
setup: deps install-lint install-air ## Setup development environment
195+
196+
# Create build directory
197+
$(BUILD_DIR):
198+
mkdir -p $(BUILD_DIR)
199+
200+
# Ensure build directory exists for build targets
201+
build: $(BUILD_DIR)
202+
build-linux: $(BUILD_DIR)
203+
build-darwin: $(BUILD_DIR)
204+
build-windows: $(BUILD_DIR)

0 commit comments

Comments
 (0)