diff --git a/bin/templates/pkg/network/grpc/constants/constants.go b/bin/templates/pkg/network/grpc/constants/constants.go index 809887d..ce84163 100644 --- a/bin/templates/pkg/network/grpc/constants/constants.go +++ b/bin/templates/pkg/network/grpc/constants/constants.go @@ -1,5 +1,28 @@ package constants -var TIMEOUT_SECONDS = 30 +import "sync" +// timeout_seconds - время ожидания ответа +var timeout_seconds int = 30 + +// TEXT_ERROR_MODEL_VERSION - текст ошибки версии модели const TEXT_ERROR_MODEL_VERSION = "Error: wrong version object model" + +// mutex_TIMEOUT_SECONDS - защита от многопоточности GetTimeoutSeconds() +var mutex_TIMEOUT_SECONDS sync.RWMutex + +// GetTimeoutSeconds - возвращает время ожидания ответа +func GetTimeoutSeconds() int { + mutex_TIMEOUT_SECONDS.RLock() + defer mutex_TIMEOUT_SECONDS.RUnlock() + + return timeout_seconds +} + +// SetTimeoutSeconds - устанавливает время ожидания ответа +func SetTimeoutSeconds(seconds int) { + mutex_TIMEOUT_SECONDS.Lock() + defer mutex_TIMEOUT_SECONDS.Unlock() + + timeout_seconds = seconds +} diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ index b0099c0..be4f07b 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ @@ -53,7 +53,7 @@ func (crud Crud_GRPC) Read(m *lawsuit_status_types.LawsuitStatusType) error { Request.VersionModel = versionModel ctxMain := context.Background() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.GetTimeoutSeconds())) defer ctxCancelFunc() // запрос @@ -97,7 +97,7 @@ func (crud Crud_GRPC) Create(m *lawsuit_status_types.LawsuitStatusType) error { Request.VersionModel = VersionModel ctxMain := context.Background() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.GetTimeoutSeconds())) defer ctxCancelFunc() // запрос @@ -141,7 +141,7 @@ func (crud Crud_GRPC) Update(m *lawsuit_status_types.LawsuitStatusType) error { Request.VersionModel = VersionModel ctxMain := context.Background() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.GetTimeoutSeconds())) defer ctxCancelFunc() // запрос @@ -185,7 +185,7 @@ func (crud Crud_GRPC) Save(m *lawsuit_status_types.LawsuitStatusType) error { Request.VersionModel = VersionModel ctxMain := context.Background() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.GetTimeoutSeconds())) defer ctxCancelFunc() // запрос @@ -225,7 +225,7 @@ func (crud Crud_GRPC) Delete(m *lawsuit_status_types.LawsuitStatusType) error { Request.VersionModel = VersionModel ctxMain := context.Background() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.GetTimeoutSeconds())) defer ctxCancelFunc() // запрос @@ -265,7 +265,7 @@ func (crud Crud_GRPC) Restore(m *lawsuit_status_types.LawsuitStatusType) error { Request.VersionModel = VersionModel ctxMain := context.Background() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.GetTimeoutSeconds())) defer ctxCancelFunc() // запрос @@ -304,7 +304,7 @@ func (crud Crud_GRPC) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) er Request.VersionModel = VersionModel ctxMain := context.Background() - ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.GetTimeoutSeconds())) defer ctxCancelFunc() //запрос diff --git a/bin/templates/pkg/network/nrpc/nrpc_client/constants/constants.go b/bin/templates/pkg/network/nrpc/nrpc_client/constants/constants.go new file mode 100644 index 0000000..ce84163 --- /dev/null +++ b/bin/templates/pkg/network/nrpc/nrpc_client/constants/constants.go @@ -0,0 +1,28 @@ +package constants + +import "sync" + +// timeout_seconds - время ожидания ответа +var timeout_seconds int = 30 + +// TEXT_ERROR_MODEL_VERSION - текст ошибки версии модели +const TEXT_ERROR_MODEL_VERSION = "Error: wrong version object model" + +// mutex_TIMEOUT_SECONDS - защита от многопоточности GetTimeoutSeconds() +var mutex_TIMEOUT_SECONDS sync.RWMutex + +// GetTimeoutSeconds - возвращает время ожидания ответа +func GetTimeoutSeconds() int { + mutex_TIMEOUT_SECONDS.RLock() + defer mutex_TIMEOUT_SECONDS.RUnlock() + + return timeout_seconds +} + +// SetTimeoutSeconds - устанавливает время ожидания ответа +func SetTimeoutSeconds(seconds int) { + mutex_TIMEOUT_SECONDS.Lock() + defer mutex_TIMEOUT_SECONDS.Unlock() + + timeout_seconds = seconds +}