/
client.go
51 lines (43 loc) · 1.18 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
package sgroups
import (
"context"
grpc_client "github.com/H-BF/sgroups/internal/grpc-client"
grpcClient "github.com/H-BF/corlib/client/grpc"
sg "github.com/H-BF/protos/pkg/api/sgroups"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
type (
// Client SecGrpups server client
Client struct {
sg.SecGroupServiceClient
}
// ClosableClient SecGrpups server client
ClosableClient struct {
sg.SecGroupServiceClient
grpcClient.Closable
}
)
// NewClient constructs 'sgroups' API Client
func NewClient(c grpc.ClientConnInterface) Client {
return Client{
SecGroupServiceClient: sg.NewSecGroupServiceClient(
grpcClient.WithErrorWrapper(c, "sgroups"),
),
}
}
// NewClosableClient constructs closable 'sgroups' API Client
func NewClosableClient(ctx context.Context, p grpc_client.ConnProvider) (ClosableClient, error) {
const api = "sgroups/new-closable-client"
c, err := p.New(ctx)
if err != nil {
return ClosableClient{}, errors.WithMessage(err, api)
}
closable := grpcClient.MakeCloseable(
grpcClient.WithErrorWrapper(c, "sgroups"),
)
return ClosableClient{
SecGroupServiceClient: sg.NewSecGroupServiceClient(closable),
Closable: closable,
}, nil
}