GOHOSTOS:=$(shell go env GOHOSTOS)
GOPATH:=$(shell go env GOPATH)
VERSION=$(shell git describe --tags --always)


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)))
	Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
	INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
	API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto")
else
	INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
	API_PROTO_FILES=$(shell find api -name *.proto)
endif

.PHONY: apigen
# 根据api创建http文件
apigen:
	cd cmd/api/doc && goctl api go -api *.api -dir ../  --style=goZero

.PHONY: rpcgen
# 根据protoc创建rpc文件
rpcgen:
	cd cmd/rpc/pb && goctl rpc protoc *.proto --go_out=../pb --go-grpc_out=../pb  --zrpc_out=../ --client=false --style=goZero

.PHONY: apiinitrpc
# api端生成rpc
apiinitrpc:
	cd rpc  && goctl rpc protoc *.proto --go_out=./ --go-grpc_out=./ --zrpc_out=./  --client=true --style=goZero && rm -r etc && rm -r internal && rm *.go


.PHONY: rpcrun
# 运行rpc
rpcrun:
	cd cmd/rpc && go run transfer.go


.PHONY: apirun
# 运行rpc
apirun:
	cd cmd/api && go run transfer.go

.PHONY: apivalidate
# 运行rpc
apivalidate:
	cd cmd/api/doc && goctl api validate --api *.api

.PHONY: apiformat
# 运行rpc
apiformat:
	cd cmd/api/doc && goctl api format --dir ./

.PHONY: apitodoc
# 运行rpc
apitodoc:
	cd cmd/api/doc && goctl api doc --dir ./


.PHONY: templateUpdate
# rpcdocker
templateUpdate:
	cd template && goctl template update   --home ./


.PHONY: rpcdocker
# rpcdocker
rpcdocker:
	 goctl docker -go ./cmd/rpc/transfer.go