From ac925c3424cccd16440fac0bb95602014e353c11 Mon Sep 17 00:00:00 2001 From: "huangsimin@fusen.cn" Date: Wed, 13 Dec 2023 17:08:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8grpc?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E5=9C=A8=E9=A1=B9=E7=9B=AE=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goutils/proto_build/main.go | 33 +++++++++++++++++--- goutils/proto_build/tpls/auto_grpc_nacos.tpl | 5 +++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/goutils/proto_build/main.go b/goutils/proto_build/main.go index d34113b..69dcef7 100644 --- a/goutils/proto_build/main.go +++ b/goutils/proto_build/main.go @@ -127,16 +127,13 @@ go run -gcflags="-N" proto/goutils/proto_build/main.go client` log.Println(err) } - projectName := "" - projectLastName := "" - ServiceName := "" + projectName := "gitlab.fusenpack.com/backend/grpc" CheckGomodBasicPackage() ExecProtoc(workspaceDir, serviceProtoDir, genDir, packageName, projectName) + GitignoreGenCheck() - ExecCreateConfig(ServiceName, projectLastName) ExecCreateAutoGrpc(genDir, packageName) - ExecCreateAutoLogic(workspaceDir, ServiceName, genDir, packageName, projectLastName) } func ExecCreateConfig(ServiceName, ProjectName string) { @@ -887,6 +884,7 @@ func importFileCmdStr(importFile string, projectName string) string { log.Printf("模板执行失败:%v\n", err) return "" } + // log.Println(buf.String()) return buf.String() } @@ -1531,3 +1529,28 @@ func getGrpcFileServiceName(decl ast.Decl) (string, string, bool) { } return "", "", false } + +// 检测gitignore gen是否存在 +func GitignoreGenCheck() { + + gitignoreFile := "./.gitignore" + + data, err := os.ReadFile(gitignoreFile) + if err != nil { + log.Println(err.Error()) + return + } + + for _, line := range strings.Split(string(data), "\n") { + if strings.Trim(line, " ") == "gen" { + return + } + } + + data = append(data, []byte("\ngen\n")...) + + err = os.WriteFile(gitignoreFile, data, 0644) + if err != nil { + panic(err) + } +} diff --git a/goutils/proto_build/tpls/auto_grpc_nacos.tpl b/goutils/proto_build/tpls/auto_grpc_nacos.tpl index 6233c14..9cdb510 100644 --- a/goutils/proto_build/tpls/auto_grpc_nacos.tpl +++ b/goutils/proto_build/tpls/auto_grpc_nacos.tpl @@ -4,6 +4,7 @@ import ( "fmt" "log" "reflect" + "fusen-basic/env" "github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client" "github.com/nacos-group/nacos-sdk-go/v2/vo" @@ -14,6 +15,10 @@ import ( var namingClient naming_client.INamingClient var groupName string +func init() { + AutoGrpcInit(env.StartAutoGrpc()) +} + // AutoGrpcInit auto grpc 必须调用初始化 func AutoGrpcInit(obj any) { value := reflect.ValueOf(obj)