-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangyile
committed
Oct 12, 2024
1 parent
94d0a3f
commit 52fd539
Showing
7 changed files
with
227 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helloworld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
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) | ||
#想把第三方的这些也收集下来,再使用命令生成第三方包(因为自动生成好像不是很好使) | ||
THIRD_PARTY_GOOGLE_API_PROTO_FILES=$(shell find third_party/google/api -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 | ||
go install github.com/google/wire/cmd/wire@latest | ||
|
||
.PHONY: config | ||
# generate internal proto | ||
config: | ||
protoc --proto_path=./internal \ | ||
--proto_path=./third_party \ | ||
--go_out=paths=source_relative:./internal \ | ||
$(INTERNAL_PROTO_FILES) | ||
|
||
.PHONY: api | ||
# generate api proto | ||
api: | ||
protoc --proto_path=./api \ | ||
--proto_path=./third_party \ | ||
--go_out=paths=source_relative:./api \ | ||
--go-http_out=paths=source_relative:./api \ | ||
--go-grpc_out=paths=source_relative:./api \ | ||
--openapi_out=fq_schema_naming=true,default_response=false:. \ | ||
$(API_PROTO_FILES) | ||
|
||
.PHONY: build | ||
# build | ||
build: | ||
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... | ||
|
||
.PHONY: generate | ||
# generate | ||
generate: | ||
go generate ./... | ||
go mod tidy | ||
|
||
.PHONY: all | ||
# generate all | ||
all: | ||
make api; | ||
make config; | ||
make generate; | ||
|
||
|
||
web_api_grpc_ts: | ||
mkdir -p ./bin/web_api_grpc_ts.out | ||
protoc \ | ||
--plugin=protoc-gen-ts=/Users/admin/.nvm/versions/node/v18.17.0/bin/protoc-gen-ts \ | ||
--ts_out=./bin/web_api_grpc_ts.out \ | ||
--proto_path=./api \ | ||
--proto_path=./third_party \ | ||
$(API_PROTO_FILES) | ||
|
||
protoc \ | ||
--plugin=protoc-gen-ts=/Users/admin/.nvm/versions/node/v18.17.0/bin/protoc-gen-ts \ | ||
--ts_out=./bin/web_api_grpc_ts.out \ | ||
--proto_path=./third_party \ | ||
$(THIRD_PARTY_GOOGLE_API_PROTO_FILES) | ||
|
||
# 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, ":")); \ | ||
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ | ||
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ | ||
} \ | ||
} \ | ||
{ lastLine = $$0 }' $(MAKEFILE_LIST) | ||
|
||
.DEFAULT_GOAL := help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
在这里使用 kratos 的 helloworld 项目,就可以体验工具。 | ||
|
||
https://go-kratos.dev/docs/getting-started/start/ | ||
|
||
根据官方网站的指导,在当前目录里,创建 helloworld 项目。 | ||
|
||
使用 make all 和 make build 把它跑起来。 | ||
|
||
接着修改其Makefile的内容。 | ||
|
||
我在这里放了个Makefile,使用它,替换 helloworld 里面的。 | ||
|
||
就可以使用这个文件里的子命令得到 typescript 的客户端代码。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters