customer/pkg/customer_clients/rpc.go

50 lines
1.5 KiB
Go
Raw Normal View History

2024-05-26 13:37:36 +00:00
package customer_clients
import (
"context"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/customer"
)
type CustomersClientDeps struct {
Logger *zap.Logger
CustomerServiceHost string
}
type CustomersClient struct {
logger *zap.Logger
customerServiceHost string
}
func NewCustomersClient(deps CustomersClientDeps) *CustomersClient {
return &CustomersClient{
logger: deps.Logger,
customerServiceHost: deps.CustomerServiceHost,
}
}
func (receiver *CustomersClient) SetVerifyAccount(ctx context.Context, req *customer.SetVerificationReq) (*customer.Account, error) {
connection, err := grpc.Dial(receiver.customerServiceHost, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
receiver.logger.Error("failed to connect on <SetVerifyAccount> of <CustomerClient>", zap.Error(err), zap.String("customer host", receiver.customerServiceHost))
return nil, err
}
defer func() {
if closeErr := connection.Close(); closeErr != nil {
receiver.logger.Error("failed to close connection on <SetVerifyAccount> of <CustomerClient>", zap.Error(closeErr))
}
}()
client := customer.NewCustomerServiceClient(connection)
account, err := client.SetAccountVerificationStatus(ctx, req)
if err != nil {
receiver.logger.Error("failed Set Account Verification Status on <SetVerifyAccount> of <CustomerClient>", zap.Error(err))
return nil, err
}
return account, nil
}