-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
76 lines (63 loc) · 2.26 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
GOBIN=$(shell pwd)/bin
GOFILES=main.go
GONAME=$(shell basename "$(PWD)")
PID=/tmp/go-$(GONAME).pid
## Display this help text
help:
$(info Available Targets)
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
nb = sub( /^## /, "", helpMsg ); \
if(nb == 0) { \
helpMsg = $$0; \
nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
} \
if (nb) \
printf "\033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
} \
{ helpMsg = $$0 }' \
$(MAKEFILE_LIST) | column -ts:
## build the repo
build:
@echo "Building $(GOFILES) to ./bin"
go build -o bin/$(GONAME) main.go
## get all the dependencies
get:
@GOBIN=$(GOBIN) go get main.go
## installs all the dependencies
install:
go install $(GOFILES)
## runs the build
run:
go run $(GOFILES)
## This is for development. Restarts after every save
watch:
@$(MAKE) restart &
@fswatch -o . -e 'bin/.*' -ignore='Path vendor' | xargs -n1 -I{} make restart
restart: clear stop clean build start
format: ## Format go code with goimports
@go get golang.org/x/tools/cmd/goimports
@goimports -l -w .
format-check: ## Check if the code is formatted
@go get golang.org/x/tools/cmd/goimports
@for i in $$(goimports -l .); do echo "[ERROR] Code is not formated run 'make format'" && exit 1; done
check: format-check ## Linting and static analysis
@if grep -r --include='*.go' -E "fmt.Print|spew.Dump" *; then \
echo "code contains fmt.Print* or spew.Dump function"; \
exit 1; \
fi
@if test ! -e ./bin/golangci-lint; then \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh; \
fi
@./bin/golangci-lint run --timeout 180s -E gosec -E stylecheck -E golint -E goimports
start: ## start defending on localmachine
@echo "Starting bin/$(GONAME)"
@./bin/$(GONAME) & echo $$! > $(PID)
stop: ## stop defending on localmachine
@echo "Stopping bin/$(GONAME) if it's running"
@-kill `[[ -f $(PID) ]] && cat $(PID)` 2>/dev/null || true
clear: ## clear
@clear
clean: ## clean
@echo "Cleaning"
@GOBIN=$(GOBIN) go clean
.PHONY: format check build get install run watch start stop restart clean