You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

172 lines
6.1 KiB

GOHOSTOS:=$(shell go env GOHOSTOS)
GOPATH:=$(shell go env GOPATH)
VERSION=$(shell git describe --tags --always)
file_name=wallet
CUR_PATH = gateway/v1
SUBINCS = $(shell ls $(CUR_PATH))
INC_FLAGS += $(foreach n,$(SUBINCS),$(wildcard ./$(CUR_PATH)/$(n)/*.proto))
GO_INC_FLAGS += $(foreach n,$(SUBINCS),$(wildcard ./$(CUR_PATH)/$(n)/*.pb.go))
SRCS=11
ifeq ($(GOHOSTOS), windows)
#the `find.exe` is different from `find` in bash/shell.
#to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
#changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
Git_Bash= $(subst cmd\,bin\bash.exe,$(dir $(shell where git)))
INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
ERROR_PROTO_FILES=$(shell $(Git_Bash) -c "error internal -name *.proto")
COMMON_PROTO_FILES=$(shell $(Git_Bash) -c "common internal -name *.proto")
API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto")
GATEWAY_ERROR_FILES=$(shell $(Git_Bash) -c "error/http_error internal -name *.proto")
else
INTERNAL_PROTO_FILES=$(shell find conf -name *.proto)
ERRORL_PROTO_FILES=$(shell find error -name *.proto)
COMMON_PROTO_FILES=$(shell find common -name *.proto)
API_PROTO_FILES=$(shell find api -name *.proto)
GATEWAY_ERROR_FILES=$(shell find error/http_error -name *.proto)
endif
.PHONY: init
# init env
init:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
.PHONY: config
# generate internal proto
config:
protoc --proto_path=./conf \
--go_out=paths=source_relative:./conf \
$(INTERNAL_PROTO_FILES)
err:
protoc --proto_path=./error \
--proto_path=./third_party \
--go_out=paths=source_relative:./error \
--go-errors_out=paths=source_relative:./error \
$(ERRORL_PROTO_FILES)
.PHONY: http-err
http-err:
protoc --proto_path=. \
--proto_path=./third_party \
--go_out=paths=source_relative:. \
--go-errors_out=paths=source_relative:. \
$(GATEWAY_ERROR_FILES)
.PHONY: common
common:
protoc --proto_path=. \
--proto_path=./third_party \
--go_out=paths=source_relative:. \
$(COMMON_PROTO_FILES)
ls common/*.pb.go | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'
.PHONY: build
# build
build:
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
run:
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
./bin/examples
.PHONY: generate
# generate
generate:
go mod tidy
go get github.com/google/wire/cmd/wire@latest
go generate ./...
.PHONY: all
# generate all
all:
make api;
make config;
make generate;
# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
# conf 文件更新
confi:
go get -u google.golang.org/protobuf/reflect/protoreflect
go get -u google.golang.org/protobuf/runtime/protoimpl
go get -u google.golang.org/protobuf/types/known/durationpb
kratos proto client conf/conf.proto
.PHONY: generate-api
generate-api:
kratos proto client $(file_name)/v1/*.proto
ls $(file_name)/v1/*.pb.go | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'
.PHONY: grpc2
grpc2:
kratos proto client $(file_name)/v2/$(file_name).proto
ls $(file_name)/v2/*.pb.go | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'
.PHONY: generate-swagger
generate-swagger:
protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. --openapiv2_opt logtostderr=true $(file_name)/v1/$(file_name).proto
protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. \
--openapiv2_opt logtostderr=true --openapiv2_opt output_format=yaml $(file_name)/v1/$(file_name).proto
.PHONY: api
api: generate-api generate-swagger
.PHONY: grpc
grpc: generate-api
.PHONY: generate-gateway-api
generate-gateway-api:
for dir in $(INC_FLAGS);\
do \
kratos proto client $$dir; \
ls $$dir | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'; \
protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. --openapiv2_opt logtostderr=true $$dir; \
protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. \
--openapiv2_opt logtostderr=true --openapiv2_opt output_format=yaml $$dir; \
done
for dir in $(GO_INC_FLAGS);\
do \
ls $$dir | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'; \
done
.PHONY: generate-app-gateway-api
generate-app-gateway-api:
for dir in app_gateway/v1/*.proto;\
do \
kratos proto client $$dir; \
done
for dir in app_gateway/v1/*.pb.go;\
do \
ls $$dir | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'; \
done
protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. --openapiv2_opt logtostderr=true app_gateway/v1/*gateway.proto; \
protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. \
--openapiv2_opt logtostderr=true --openapiv2_opt output_format=yaml app_gateway/v1/*gateway.proto;
#protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. --openapiv2_opt logtostderr=true app_gateway/v1/guild_gateway.proto; \
# protoc --proto_path=. --proto_path=./third_party --openapiv2_out json_names_for_fields=false:. \
# --openapiv2_opt logtostderr=true --openapiv2_opt output_format=yaml app_gateway/v1/guild_gateway.proto;