-
Notifications
You must be signed in to change notification settings - Fork 68
/
client.go
146 lines (134 loc) · 3.68 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Code generated by goa v3.16.2, DO NOT EDIT.
//
// storage gRPC client
//
// Command:
// $ goa gen goa.design/examples/cellar/design
package client
import (
"context"
storagepb "goa.design/examples/cellar/gen/grpc/storage/pb"
goagrpc "goa.design/goa/v3/grpc"
goapb "goa.design/goa/v3/grpc/pb"
goa "goa.design/goa/v3/pkg"
"google.golang.org/grpc"
)
// Client lists the service endpoint gRPC clients.
type Client struct {
grpccli storagepb.StorageClient
opts []grpc.CallOption
}
// NewClient instantiates gRPC client for all the storage service servers.
func NewClient(cc *grpc.ClientConn, opts ...grpc.CallOption) *Client {
return &Client{
grpccli: storagepb.NewStorageClient(cc),
opts: opts,
}
}
// List calls the "List" function in storagepb.StorageClient interface.
func (c *Client) List() goa.Endpoint {
return func(ctx context.Context, v any) (any, error) {
inv := goagrpc.NewInvoker(
BuildListFunc(c.grpccli, c.opts...),
nil,
DecodeListResponse)
res, err := inv.Invoke(ctx, v)
if err != nil {
return nil, goa.Fault(err.Error())
}
return res, nil
}
}
// Show calls the "Show" function in storagepb.StorageClient interface.
func (c *Client) Show() goa.Endpoint {
return func(ctx context.Context, v any) (any, error) {
inv := goagrpc.NewInvoker(
BuildShowFunc(c.grpccli, c.opts...),
EncodeShowRequest,
DecodeShowResponse)
res, err := inv.Invoke(ctx, v)
if err != nil {
resp := goagrpc.DecodeError(err)
switch message := resp.(type) {
case *storagepb.ShowNotFoundError:
return nil, NewShowNotFoundError(message)
case *goapb.ErrorResponse:
return nil, goagrpc.NewServiceError(message)
default:
return nil, goa.Fault(err.Error())
}
}
return res, nil
}
}
// Add calls the "Add" function in storagepb.StorageClient interface.
func (c *Client) Add() goa.Endpoint {
return func(ctx context.Context, v any) (any, error) {
inv := goagrpc.NewInvoker(
BuildAddFunc(c.grpccli, c.opts...),
EncodeAddRequest,
DecodeAddResponse)
res, err := inv.Invoke(ctx, v)
if err != nil {
return nil, goa.Fault(err.Error())
}
return res, nil
}
}
// Remove calls the "Remove" function in storagepb.StorageClient interface.
func (c *Client) Remove() goa.Endpoint {
return func(ctx context.Context, v any) (any, error) {
inv := goagrpc.NewInvoker(
BuildRemoveFunc(c.grpccli, c.opts...),
EncodeRemoveRequest,
nil)
res, err := inv.Invoke(ctx, v)
if err != nil {
return nil, goa.Fault(err.Error())
}
return res, nil
}
}
// Rate calls the "Rate" function in storagepb.StorageClient interface.
func (c *Client) Rate() goa.Endpoint {
return func(ctx context.Context, v any) (any, error) {
inv := goagrpc.NewInvoker(
BuildRateFunc(c.grpccli, c.opts...),
EncodeRateRequest,
nil)
res, err := inv.Invoke(ctx, v)
if err != nil {
return nil, goa.Fault(err.Error())
}
return res, nil
}
}
// MultiAdd calls the "MultiAdd" function in storagepb.StorageClient interface.
func (c *Client) MultiAdd() goa.Endpoint {
return func(ctx context.Context, v any) (any, error) {
inv := goagrpc.NewInvoker(
BuildMultiAddFunc(c.grpccli, c.opts...),
EncodeMultiAddRequest,
DecodeMultiAddResponse)
res, err := inv.Invoke(ctx, v)
if err != nil {
return nil, goa.Fault(err.Error())
}
return res, nil
}
}
// MultiUpdate calls the "MultiUpdate" function in storagepb.StorageClient
// interface.
func (c *Client) MultiUpdate() goa.Endpoint {
return func(ctx context.Context, v any) (any, error) {
inv := goagrpc.NewInvoker(
BuildMultiUpdateFunc(c.grpccli, c.opts...),
EncodeMultiUpdateRequest,
nil)
res, err := inv.Invoke(ctx, v)
if err != nil {
return nil, goa.Fault(err.Error())
}
return res, nil
}
}