-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
146 lines (117 loc) · 3.25 KB
/
Makefile
File metadata and controls
146 lines (117 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
BINARY_NAME=main
BINARY_UNIX=$(BINARY_NAME)_unix
# Docker parameters
DOCKER_IMAGE=user-management-api
DOCKER_TAG=latest
.PHONY: all build clean test coverage deps lint docker-build docker-run docker-stop help
all: test build
## Build the application
build:
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/server
## Build for Linux
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v ./cmd/server
## Clean build files
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)
## Run tests
test:
$(GOTEST) -v ./...
## Run tests with coverage
coverage:
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
## Download dependencies
deps:
$(GOMOD) download
$(GOMOD) tidy
## Run linter
lint:
golangci-lint run
## Fix linting issues
lint-fix:
golangci-lint run --fix
## Install linter
install-linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
## Run the application
run:
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/server
./$(BINARY_NAME)
## Run with hot reload (requires air)
dev:
air
## Install air for hot reload
install-air:
go install github.com/cosmtrek/air@latest
## Generate Swagger docs
swagger:
swag init -g cmd/server/main.go -o docs
## Install swagger
install-swagger:
go install github.com/swaggo/swag/cmd/swag@latest
## Docker build
docker-build:
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
## Docker run with compose
docker-up:
docker-compose up -d
## Docker stop
docker-down:
docker-compose down
## Docker logs
docker-logs:
docker-compose logs -f api
## Create uploads directory
create-dirs:
mkdir -p uploads/images uploads/documents
## Setup development environment
setup: deps install-linter install-swagger install-air create-dirs
@echo "Development environment setup complete!"
## Format code
fmt:
$(GOCMD) fmt ./...
## Vet code
vet:
$(GOCMD) vet ./...
## Security check
security:
gosec ./...
## Install security checker
install-security:
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest
## Full check (format, vet, lint, test)
check: fmt vet lint test
## Help
help:
@echo "Available commands:"
@echo " build - Build the application"
@echo " build-linux - Build for Linux"
@echo " clean - Clean build files"
@echo " test - Run tests"
@echo " coverage - Run tests with coverage"
@echo " deps - Download dependencies"
@echo " lint - Run linter"
@echo " lint-fix - Fix linting issues"
@echo " run - Build and run the application"
@echo " dev - Run with hot reload"
@echo " swagger - Generate Swagger docs"
@echo " docker-build - Build Docker image"
@echo " docker-up - Start with Docker Compose"
@echo " docker-down - Stop Docker Compose"
@echo " docker-logs - View Docker logs"
@echo " setup - Setup development environment"
@echo " fmt - Format code"
@echo " vet - Vet code"
@echo " security - Run security check"
@echo " check - Run all checks"
@echo " help - Show this help"