forked from Netflix/conductor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
75 lines (65 loc) · 2.02 KB
/
client.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package gogrpc
import (
"github.com/mactaggart/conductor/client/gogrpc/service"
grpc "google.golang.org/grpc"
)
// TasksClient is a Conductor client that exposes the Conductor
// Tasks API.
type TasksClient interface {
Tasks() tasks.TaskServiceClient
Shutdown()
}
// MetadataClient is a Conductor client that exposes the Conductor
// Metadata API.
type MetadataClient interface {
Metadata() metadata.MetadataServiceClient
Shutdown()
}
// WorkflowsClient is a Conductor client that exposes the Conductor
// Workflows API.
type WorkflowsClient interface {
Workflows() workflows.WorkflowServiceClient
Shutdown()
}
// Client encapsulates a GRPC connection to a Conductor server and
// the different services it exposes.
type Client struct {
conn *grpc.ClientConn
tasks tasks.TaskServiceClient
metadata metadata.MetadataServiceClient
workflows workflows.WorkflowServiceClient
}
// NewClient returns a new Client with a GRPC connection to the given address,
// and any optional grpc.Dialoption settings.
func NewClient(address string, options ...grpc.DialOption) (*Client, error) {
conn, err := grpc.Dial(address, options...)
if err != nil {
return nil, err
}
return &Client{conn: conn}, nil
}
// Shutdown closes the underlying GRPC connection for this client.
func (client *Client) Shutdown() {
client.conn.Close()
}
// Tasks returns the Tasks service for this client
func (client *Client) Tasks() tasks.TaskServiceClient {
if client.tasks == nil {
client.tasks = tasks.NewTaskServiceClient(client.conn)
}
return client.tasks
}
// Metadata returns the Metadata service for this client
func (client *Client) Metadata() metadata.MetadataServiceClient {
if client.metadata == nil {
client.metadata = metadata.NewMetadataServiceClient(client.conn)
}
return client.metadata
}
// Workflows returns the workflows service for this client
func (client *Client) Workflows() workflows.WorkflowServiceClient {
if client.workflows == nil {
client.workflows = workflows.NewWorkflowServiceClient(client.conn)
}
return client.workflows
}