From aa46709a6b48a3c8b32e4aae36ea32d006649aa8 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Thu, 25 Jan 2024 13:02:46 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20timeout?= =?UTF-8?q?=5Fseconds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../network/grpc/grpc_client/grpc_client.go_ | 16 ++++++++++++++++ .../{nrpc_client => }/constants/constants.go | 0 .../network/nrpc/nrpc_client/nrpc_client.go_ | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) rename bin/templates/pkg/network/nrpc/{nrpc_client => }/constants/constants.go (100%) diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client.go_ index a4f28eb..b3f156a 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client.go_ @@ -9,6 +9,7 @@ import ( "github.com/ManyakRus/starter/stopapp" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + grpc_constants "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/constants" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "os" @@ -71,6 +72,9 @@ func Connect_err() error { addr := Settings.SYNC_SERVICE_HOST + ":" + Settings.SYNC_SERVICE_PORT Conn, err = grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return err + } Client = grpc_proto.NewSyncServiceClient(Conn) return err @@ -219,3 +223,15 @@ loop: stopapp.GetWaitGroup_Main().Done() } + +// GetTimeoutSeconds - возвращает время ожидания ответа +func GetTimeoutSeconds() int { + Otvet := grpc_constants.GetTimeoutSeconds() + + return Otvet +} + +// SetTimeoutSeconds - устанавливает время ожидания ответа +func SetTimeoutSeconds(seconds int) { + grpc_constants.SetTimeoutSeconds(seconds) +} diff --git a/bin/templates/pkg/network/nrpc/nrpc_client/constants/constants.go b/bin/templates/pkg/network/nrpc/constants/constants.go similarity index 100% rename from bin/templates/pkg/network/nrpc/nrpc_client/constants/constants.go rename to bin/templates/pkg/network/nrpc/constants/constants.go diff --git a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ index a5e168e..c6b03dd 100644 --- a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ +++ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ @@ -16,6 +16,7 @@ import ( "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/pkg/db/constants" + nrpc_constants "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/constants" "sync" "os" @@ -72,12 +73,12 @@ func Connect_err() error { } NatsURL := "nats://" + Settings.NATS_HOST + ":" + Settings.NATS_PORT + // Connect to the NATS server. Conn, err = nats.Connect(NatsURL, nats.Timeout(5*time.Second)) if err != nil { - log.Panic(err) + return err } - // defer Conn.Close() // This is our generated client. Client = grpc_proto.NewSync_serviceClient(Conn) @@ -230,3 +231,15 @@ loop: stopapp.GetWaitGroup_Main().Done() } + +// GetTimeoutSeconds - возвращает время ожидания ответа +func GetTimeoutSeconds() int { + Otvet := nrpc_constants.GetTimeoutSeconds() + + return Otvet +} + +// SetTimeoutSeconds - устанавливает время ожидания ответа +func SetTimeoutSeconds(seconds int) { + nrpc_constants.SetTimeoutSeconds(seconds) +}