-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
83 lines (64 loc) · 2.01 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
PROJECTNAME=$(shell basename "$(PWD)")
# Go related variables.
GOBASE=$(shell pwd)
GOBIN=$(GOBASE)/bin
CONFIG=$(GOBASE)/config.yaml
# Redirect error output to a file, so we can show it in development mode.
STDERR=~/.$(PROJECTNAME)-stderr.txt
# PID file will store the server process id when it's running on development mode
PID=~/.$(PROJECTNAME)-api-server.pid
# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent
.PHONY: help
all: help
## start: Start server.
start: start-server
## stop: Stop server.
stop: stop-server
## restart: restart server.
restart: restart-server
## install: Install missing dependencies. Runs `go get` internally.
install: go-get
## build: build server
build: go-build
## generate: generate Gormgen CURD and gRPC code
generate: generate-gorm-gen-code generate-buf
#生成Gormgen CURD代码
generate-gorm-gen-code:
@echo "Start Generating"
go run $(GOBASE)/cmd/gormgen
#gRPC service
generate-buf:
buf generate --path $(GOBASE)/proto/server/server.proto
clean-buf:
rm $(GOBASE)/proto/server/*.go
rm $(GOBASE)/proto/server/*.json
install-tools:
go install \
github.com/bufbuild/buf/cmd/buf@lastest \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@lastest \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@lastest \
google.golang.org/grpc/cmd/protoc-gen-go-grpc@lastest \
google.golang.org/protobuf/cmd/protoc-gen-go@lastest
go-get:
@echo " > Checking if there is any missing dependencies..."
@go get $(get)
go-build:
@echo " > Building binary..."
@go build -o $(GOBIN)/$(PROJECTNAME)
start-server:
@echo " > Start $(PROJECTNAME)"
@$(GOBIN)/$(PROJECTNAME) server -c $(CONFIG) 2>&1 & echo $$! > $(PID)
@cat $(PID) | sed "/^/s/^/ \> PID: /"
stop-server:
@echo " > Stop server"
@-touch $(PID)
@-kill `cat $(PID)` 2> /dev/null || true
@-rm $(PID)
restart-server: stop-server start-server
help: Makefile
@echo
@echo " Choose a command run in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo