-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.go
More file actions
32 lines (26 loc) · 735 Bytes
/
connect.go
File metadata and controls
32 lines (26 loc) · 735 Bytes
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
package lights
import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/akrantz01/lights/api/lights/pb"
)
// Controller is a wrapper around a pb.ControllerClient to make it easier to work with.
type Controller struct {
conn *grpc.ClientConn
inner pb.ControllerClient
}
// Connect starts an RPC connection to the controller
func Connect(address string) (*Controller, error) {
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
return &Controller{
conn: conn,
inner: pb.NewControllerClient(conn),
}, nil
}
// Close disconnects from the server
func (c *Controller) Close() error {
return c.conn.Close()
}