-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
102 lines (78 loc) · 2.13 KB
/
Makefile
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
# Constants
PROJECT_NAME = 'go-backend-template'
DB_URL = 'postgres://go-backend-template:go-backend-template@localhost:5454/go-backend-template?sslmode=disable'
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
else
DETECTED_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif
# Help
.SILENT: help
help:
@echo
@echo "Usage: make [command]"
@echo
@echo "Commands:"
@echo " rename-project name={name} Rename project"
@echo
@echo " build-http Build http server"
@echo
@echo " migration-create name={name} Create migration"
@echo " migration-up Up migrations"
@echo " migration-down Down last migration"
@echo
@echo " docker-up Up docker services"
@echo " docker-down Down docker services"
@echo
@echo " fmt Format source code"
@echo " test Run unit tests"
@echo
# Build
.SILENT: rename-project
rename-project:
ifeq ($(name),)
@echo 'new project name not set'
else
ifeq ($(DETECTED_OS),Darwin)
@grep -RiIl '$(PROJECT_NAME)' | xargs sed -i '' 's/$(PROJECT_NAME)/$(name)/g'
endif
ifeq ($(DETECTED_OS),Linux)
@grep -RiIl '$(PROJECT_NAME)' | xargs sed -i 's/$(PROJECT_NAME)/$(name)/g'
endif
ifeq ($(DETECTED_OS),Windows)
@grep 'target is not implemented on Windows platform'
endif
endif
.SILENT: build-http
build-http:
@go build -o ./bin/http-server ./cmd/http/main.go
@echo executable file \"http-server\" saved in ./bin/http-server
# Test
.SILENT: test
test:
@go test ./... -v
# Create migration
.SILENT: migration-create
migration-create:
@migrate create -ext sql -dir ./migrations -seq $(name)
# Up migration
.SILENT: migration-up
migration-up:
@migrate -database $(DB_URL) -path ./migrations up
# Down migration
.SILENT: "migration-down"
migration-down:
@migrate -database $(DB_URL) -path ./migrations down 1
# Docker
.SILENT: docker-up
docker-up:
@docker-compose up -d
.SILENT: docker-down
docker-down:
@docker-compose down
# Format
.SILENT: fmt
fmt:
@go fmt ./...
# Default
.DEFAULT_GOAL := help