From 7164e74b59339a60df77992da51711191fc159dd Mon Sep 17 00:00:00 2001 From: xxjwxc Date: Fri, 27 Oct 2023 17:40:04 +0800 Subject: [PATCH] 1 --- Makefile | 18 +++++++++- example/generate/proto_makefile | 62 +++++++++++++++++++-------------- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 33f10ba..c46f264 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ source_install: clear: # 删除proto文件夹下所有go文件(谨慎操作) rm -rf ./prc/**/*.go new: #make new service=example +ifeq ($(OS),Windows_NT) # windows echo start install $(service) @# 开始替换文件 @test -d $(service) || cp -r ./example/ ./$(service)/ @@ -17,4 +18,19 @@ new: #make new service=example @# 开始更新apidoc @test -d ./apidoc/proto/$(service)/ || cp -r ./apidoc/proto/example/ ./apidoc/proto/$(service)/ @sed -i 's#example#$(service)#g' ./apidoc/proto/$(service)/*.proto - @echo service $(service) success \ No newline at end of file + @echo service $(service) success +else + echo start install $(service) + @# 开始替换文件 + @test -d $(service) || cp -r ./example/ ./$(service)/ + find ./$(service)/ -type f -name "*.go" | xargs sed -i '' 's#example#$(service)#g' + @sed -i '' 's#example#$(service)#g' ./$(service)/go.mod + @sed -i '' 's#example#$(service)#g' ./$(service)/Makefile + @sed -i '' 's#example#$(service)#g' ./$(service)/generate/proto_makefile + @sed -i '' 's#example#$(service)#g' ./$(service)/conf/config.yml + @# 开始更新apidoc + @test -d ./apidoc/proto/$(service)/ || cp -r ./apidoc/proto/example/ ./apidoc/proto/$(service)/ + @sed -i '' 's#example#$(service)#g' ./apidoc/proto/$(service)/*.proto + @echo service $(service) success +endif + diff --git a/example/generate/proto_makefile b/example/generate/proto_makefile index 1ad356f..0912274 100644 --- a/example/generate/proto_makefile +++ b/example/generate/proto_makefile @@ -8,33 +8,41 @@ COMMSHELLFILE :=`ls $(APIDOCDIR)/proto/common/*.proto | cut -d'/' -f5` gen_proto: gen_build gen_base clean_proto: - rm -f rpc/common/*.pb.go + rm -f rpc/common/*.pb.go gen_build:# 自定义注册 - @mkdir -p rpc/$(NAME) - @echo "gen_build proto" - @rm -f rpc/$(NAME)/*.pb.go - @rm -f rpc/$(NAME)/*.pb.gmsec.go - @for file in $(BUILDSHELLFILE); do \ - echo build $$file; \ - protoc --proto_path="$(APIDOCDIR)/proto/" --gmsec_out=plugins=gmsec:./ $(NAME)/$$file; \ - done; - @sed -i 's/,omitempty//g' ./rpc/$(NAME)/*.pb.go #开始取消json omitempty - cp -rf ./rpc/$(NAME)/ $(RPCCDIR)/ #子目录向父目录拷贝 - #@sed -i 's#common "rpc/common"#common "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.go #开始替换common包 - #@sed -i 's#common "rpc/common"#common "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.gmsec.go #开始替换common包 - #@sed -i 's#_ "rpc/common"#_ "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.go #开始替换common包 - #@sed -i 's#_ "rpc/common"#_ "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.gmsec.go #开始替换common包 + @mkdir -p rpc/$(NAME) + @echo "gen_build proto" + @rm -f rpc/$(NAME)/*.pb.go + @rm -f rpc/$(NAME)/*.pb.gmsec.go + @for file in $(BUILDSHELLFILE); do \ + echo build $$file; \ + protoc --proto_path="$(APIDOCDIR)/proto/" --gmsec_out=plugins=gmsec:./ $(NAME)/$$file; \ + done; +ifeq ($(OS),Windows_NT) # windows + @sed -i 's/,omitempty//g' ./rpc/$(NAME)/*.pb.go #开始取消json omitempty + cp -rf ./rpc/$(NAME)/ $(RPCCDIR)/ #子目录向父目录拷贝 +else + @sed -i '' 's/,omitempty//g' ./rpc/$(NAME)/*.pb.go #开始取消json omitempty + cp -rf ./rpc/$(NAME)/ $(RPCCDIR)/$(NAME)/ #子目录向父目录拷贝 +endif + + #@sed -i 's#common "rpc/common"#common "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.go #开始替换common包 + #@sed -i 's#common "rpc/common"#common "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.gmsec.go #开始替换common包 + #@sed -i 's#_ "rpc/common"#_ "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.go #开始替换common包 + #@sed -i 's#_ "rpc/common"#_ "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.gmsec.go #开始替换common包 gen_base:# 基础库 - @mkdir -p $(RPCCDIR)/common - @echo "gen proto" - @rm -f rpc/common/*.pb.go - @rm -f rpc/common/*.pb.gmsec.go - @for file in $(COMMSHELLFILE); do \ - echo base $$file; \ - protoc --proto_path="$(APIDOCDIR)/proto/" --gmsec_out=plugins=gmsec:$(APIDOCDIR)/ common/$$file; \ - done; - @sed -i 's/,omitempty//g' $(RPCCDIR)/common/*.pb.go #开始取消json omitempty - #cp -rf $(RPCCDIR)/common/ ./rpc/ #父目录向当前目录拷贝 - - + @mkdir -p $(RPCCDIR)/common + @echo "gen proto" + @rm -f rpc/common/*.pb.go + @rm -f rpc/common/*.pb.gmsec.go + @for file in $(COMMSHELLFILE); do \ + echo base $$file; \ + protoc --proto_path="$(APIDOCDIR)/proto/" --gmsec_out=plugins=gmsec:$(APIDOCDIR)/ common/$$file; \ + done; +ifeq ($(OS),Windows_NT) # windows + @sed -i 's/,omitempty//g' $(RPCCDIR)/common/*.pb.go #开始取消json omitempty +else + @sed -i '' 's/,omitempty//g' $(RPCCDIR)/common/*.pb.go #开始取消json omitempty +endif + #cp -rf $(RPCCDIR)/common/ ./rpc/ #父目录向当前目录拷贝 \ No newline at end of file