From 62cf2a573e16fd52a7394f9df44db8b40b820239 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 29 Nov 2023 14:09:53 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/templates/Makefile_ | 5 +++-- .../network/grpc => api}/generation_code.sh_ | 0 .../{pkg/network/grpc => api}/service.proto_ | 0 .../app/grpc/server_grpc/server_grpc_func.go_ | 2 +- .../nrpc/server_nrpc/server_nrpc_starter.go_ | 18 ++++++++++++++++-- internal/config/config.go | 5 ++++- internal/create_files/create_files.go | 5 +++-- internal/create_files/makefile/makefile.go | 2 +- internal/create_files/model/model.go | 2 +- .../server_nrpc_starter/server_nrpc_starter.go | 12 ++++++++++-- 10 files changed, 39 insertions(+), 12 deletions(-) rename bin/templates/{pkg/network/grpc => api}/generation_code.sh_ (100%) rename bin/templates/{pkg/network/grpc => api}/service.proto_ (100%) diff --git a/bin/templates/Makefile_ b/bin/templates/Makefile_ index 96ce3fb..a7db086 100644 --- a/bin/templates/Makefile_ +++ b/bin/templates/Makefile_ @@ -5,7 +5,7 @@ FILEMAIN=./cmd/$(SERVICENAME)/main.go FILEAPP=./bin/$(SERVICENAME) NEW_REPO=$(SERVICENAME) -CD_GENERATION_PROTO=cd ./pkg/network/grpc +CD_GENERATION_PROTO=cd ./api GENERATION_PROTO=generation_code.sh @@ -56,4 +56,5 @@ init: go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service $(CD_GENERATION_PROTO) $(GENERATION_PROTO) - go mod tidy \ No newline at end of file + go mod tidy + go mod vendor \ No newline at end of file diff --git a/bin/templates/pkg/network/grpc/generation_code.sh_ b/bin/templates/api/generation_code.sh_ similarity index 100% rename from bin/templates/pkg/network/grpc/generation_code.sh_ rename to bin/templates/api/generation_code.sh_ diff --git a/bin/templates/pkg/network/grpc/service.proto_ b/bin/templates/api/service.proto_ similarity index 100% rename from bin/templates/pkg/network/grpc/service.proto_ rename to bin/templates/api/service.proto_ diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ index f964de6..41f5bd7 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_func.go_ @@ -3,7 +3,7 @@ package server_grpc import ( "errors" "github.com/ManyakRus/starter/micro" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/constants" ) // ErrorModelVersion diff --git a/bin/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ b/bin/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ index 4aa582f..f5b4fd0 100644 --- a/bin/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ +++ b/bin/templates/internal/app/nrpc/server_nrpc/server_nrpc_starter.go_ @@ -5,12 +5,17 @@ import ( "github.com/ManyakRus/starter/log" "github.com/ManyakRus/starter/stopapp" "github.com/nats-io/nats.go" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/internal/app/grpc/server_grpc" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" "os" + "strings" "time" ) +//// server is used to implement UnimplementedSyncServiceServer. +//type server struct { +//} + type SettingsINI struct { NATS_HOST string NATS_PORT string @@ -77,6 +82,14 @@ func FillSettings() { Settings.NATS_PORT = os.Getenv("BUS_LOCAL_PORT") } + //удалим лишний :порт + if Settings.NATS_PORT != "" { + pos1 := strings.Index(Settings.NATS_HOST, ":") + if pos1 > 0 { + Settings.NATS_HOST = Settings.NATS_HOST[0:pos1] + } + } + //проверка if Settings.NATS_HOST == "" { log.Panic("Need fill BUS_LOCAL_HOST ! in OS Environment ") @@ -89,6 +102,7 @@ func FillSettings() { // WaitStop - ожидает отмену глобального контекста func WaitStop() { + defer stopapp.GetWaitGroup_Main().Done() select { case <-contextmain.GetContext().Done(): @@ -100,7 +114,7 @@ func WaitStop() { //закрываем соединение CloseConnection() - stopapp.GetWaitGroup_Main().Done() + } // Start - необходимые процедуры для запуска сервера GRPC diff --git a/internal/config/config.go b/internal/config/config.go index 8f2cdb2..887de8a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -81,7 +81,10 @@ func FillSettings() { Settings.TEXT_TEMPLATE_TABLENAME = os.Getenv("TEXT_TEMPLATE_TABLENAME") Settings.TEMPLATE_SERVICE_NAME = os.Getenv("TEMPLATE_SERVICE_NAME") Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER = os.Getenv("TEMPLATE_FOLDERNAME_CRUD_STARTER") - Settings.SERVICE_REPOSITORY_URL = os.Getenv("SERVICE_REPOSITORY_URL") + + SERVICE_REPOSITORY_URL := strings.ToLower(os.Getenv("SERVICE_REPOSITORY_URL")) + Settings.SERVICE_REPOSITORY_URL = SERVICE_REPOSITORY_URL + Settings.TEMPLATE_FOLDERNAME_ALIAS = os.Getenv("TEMPLATE_FOLDERNAME_ALIAS") Settings.PREFIX_SERVER_GRPC = os.Getenv("PREFIX_SERVER_GRPC") diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 49b3d72..277909a 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -82,7 +82,7 @@ func DeleteFuncFromFuncName(Text, FuncName string) string { func DeleteFuncFromComment(Text, Comment string) string { Otvet := Text - TextFind := "\n// " + Comment + TextFind := Comment pos1 := strings.Index(Otvet, TextFind) if pos1 < 0 { return Otvet @@ -328,7 +328,8 @@ func FindTableNameURL(TableName string) string { func FindProtoURL() string { Otvet := "" - Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + "/" + "grpc_proto" + TEMPLATE_FOLDERNAME_GRPC_PROTO := strings.ToLower(config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO) + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + TEMPLATE_FOLDERNAME_GRPC_PROTO + "/" + "grpc_proto" return Otvet } diff --git a/internal/create_files/makefile/makefile.go b/internal/create_files/makefile/makefile.go index 67a4738..463d7f8 100644 --- a/internal/create_files/makefile/makefile.go +++ b/internal/create_files/makefile/makefile.go @@ -59,7 +59,7 @@ func CreateMakefile() error { //заполним GENERATION_PROTO VariableName = "CD_GENERATION_PROTO" - Value = "cd ./" + config.Settings.TEMPLATE_FOLDERNAME_GRPC + " && \\" + Value = "cd ./" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + " && \\" TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value) //заполним GENERATION_PROTO diff --git a/internal/create_files/model/model.go b/internal/create_files/model/model.go index 03c7a3b..39d9e14 100644 --- a/internal/create_files/model/model.go +++ b/internal/create_files/model/model.go @@ -211,7 +211,7 @@ func DeleteFunctions(Text, TableName string, MapModelCrudDeleteFunctions map[str MassDelete := strings.Split(TextDelete, ",") for _, FunctionName1 := range MassDelete { - Otvet = create_files.DeleteFuncFromComment(Otvet, FunctionName1) + Otvet = create_files.DeleteFuncFromComment(Otvet, "\n// "+FunctionName1) Otvet = create_files.DeleteFuncFromFuncName(Otvet, FunctionName1) } diff --git a/internal/create_files/server_nrpc_starter/server_nrpc_starter.go b/internal/create_files/server_nrpc_starter/server_nrpc_starter.go index 7d88a55..be02616 100644 --- a/internal/create_files/server_nrpc_starter/server_nrpc_starter.go +++ b/internal/create_files/server_nrpc_starter/server_nrpc_starter.go @@ -65,14 +65,22 @@ func CreateServerGRPCStarter() error { TextNRPCStarter = create_files.AddImport(TextNRPCStarter, RepositoryServerGRPCURL) } + //найдём текст после конца импортов + TextAfterImport := "" + pos1 := strings.Index(TextNRPCStarter, "\n)") + if pos1 >= 0 { + TextAfterImport = TextNRPCStarter[pos1+2:] + } + //заменим название сервиса ServiceName := config.Settings.SERVICE_NAME ServiceNameProto := micro.StringFromUpperCase(ServiceName) TEMPLATE_SERVICE_NAME := config.Settings.TEMPLATE_SERVICE_NAME - TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, TEMPLATE_SERVICE_NAME, ServiceNameProto) + TextAfterImport = strings.ReplaceAll(TextAfterImport, TEMPLATE_SERVICE_NAME, ServiceNameProto) //заменим ещё раз с большой буквы TEMPLATE_SERVICE_NAME = micro.StringFromUpperCase(TEMPLATE_SERVICE_NAME) - TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, TEMPLATE_SERVICE_NAME, ServiceNameProto) + TextAfterImport = strings.ReplaceAll(TextAfterImport, TEMPLATE_SERVICE_NAME, ServiceNameProto) + TextNRPCStarter = TextNRPCStarter[:pos1+2] + TextAfterImport //удаление пустого импорта TextNRPCStarter = create_files.DeleteEmptyImport(TextNRPCStarter)