-
Notifications
You must be signed in to change notification settings - Fork 0
/
project-client-service.go
45 lines (38 loc) · 1.71 KB
/
project-client-service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Package graphql implements functions to expose api-gateway service endpoint using GraphQL protocol.
package graphql
import (
"github.com/decentralized-cloud/api-gateway/services/configuration"
"github.com/decentralized-cloud/api-gateway/services/graphql/types/project"
projectGrpcContract "github.com/decentralized-cloud/project/contract/grpc/go"
commonErrors "github.com/micro-business/go-core/system/errors"
"google.golang.org/grpc"
)
type projectClientService struct {
serviceAddress string
}
// NewProjectClientService creates new instance of the projectClientService, setting up all dependencies and returns the instance
// configurationService: Mandatory. Reference to the configuration service
// Returns the new instance or error if something goes wrong
func NewProjectClientService(
configurationService configuration.ConfigurationContract) (project.ProjectClientContract, error) {
if configurationService == nil {
return nil, commonErrors.NewArgumentNilError("configurationService", "configurationService is required")
}
serviceAddress, err := configurationService.GetProjectServiceAddress()
if err != nil {
return nil, err
}
return &projectClientService{
serviceAddress: serviceAddress,
}, nil
}
// CreateClient creats a new project gRPC client and returns the connection
// and the client to the caller.
// Returns connection and the project gRPC client or error if something goes wrong.
func (service *projectClientService) CreateClient() (*grpc.ClientConn, projectGrpcContract.ProjectServiceClient, error) {
connection, err := grpc.Dial(service.serviceAddress, grpc.WithInsecure())
if err != nil {
return nil, nil, err
}
return connection, projectGrpcContract.NewProjectServiceClient(connection), nil
}