-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.connect.go
191 lines (169 loc) · 8.72 KB
/
rpc.connect.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Code generated by protoc-gen-connect-go. DO NOT EDIT.
//
// Source: clconnect/v1/rpc.proto
package clconnectv1connect
import (
connect "connectrpc.com/connect"
context "context"
errors "errors"
v1 "github.com/crewlinker/clgo/clconnect/v1"
http "net/http"
strings "strings"
)
// This is a compile-time assertion to ensure that this generated file and the connect package are
// compatible. If you get a compiler error that this constant is not defined, this code was
// generated with a version of connect newer than the one compiled into your binary. You can fix the
// problem by either regenerating this code with an older version of connect or updating the connect
// version compiled into your binary.
const _ = connect.IsAtLeastVersion1_13_0
const (
// ReadOnlyServiceName is the fully-qualified name of the ReadOnlyService service.
ReadOnlyServiceName = "clconnect.v1.ReadOnlyService"
// ReadWriteServiceName is the fully-qualified name of the ReadWriteService service.
ReadWriteServiceName = "clconnect.v1.ReadWriteService"
)
// These constants are the fully-qualified names of the RPCs defined in this package. They're
// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route.
//
// Note that these are different from the fully-qualified method names used by
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
// ReadOnlyServiceFooProcedure is the fully-qualified name of the ReadOnlyService's Foo RPC.
ReadOnlyServiceFooProcedure = "/clconnect.v1.ReadOnlyService/Foo"
// ReadWriteServiceCheckHealthProcedure is the fully-qualified name of the ReadWriteService's
// CheckHealth RPC.
ReadWriteServiceCheckHealthProcedure = "/clconnect.v1.ReadWriteService/CheckHealth"
)
// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package.
var (
readOnlyServiceServiceDescriptor = v1.File_clconnect_v1_rpc_proto.Services().ByName("ReadOnlyService")
readOnlyServiceFooMethodDescriptor = readOnlyServiceServiceDescriptor.Methods().ByName("Foo")
readWriteServiceServiceDescriptor = v1.File_clconnect_v1_rpc_proto.Services().ByName("ReadWriteService")
readWriteServiceCheckHealthMethodDescriptor = readWriteServiceServiceDescriptor.Methods().ByName("CheckHealth")
)
// ReadOnlyServiceClient is a client for the clconnect.v1.ReadOnlyService service.
type ReadOnlyServiceClient interface {
// Foo method for testing
Foo(context.Context, *connect.Request[v1.FooRequest]) (*connect.Response[v1.FooResponse], error)
}
// NewReadOnlyServiceClient constructs a client for the clconnect.v1.ReadOnlyService service. By
// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses,
// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the
// connect.WithGRPC() or connect.WithGRPCWeb() options.
//
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
// http://api.acme.com or https://acme.com/grpc).
func NewReadOnlyServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ReadOnlyServiceClient {
baseURL = strings.TrimRight(baseURL, "/")
return &readOnlyServiceClient{
foo: connect.NewClient[v1.FooRequest, v1.FooResponse](
httpClient,
baseURL+ReadOnlyServiceFooProcedure,
connect.WithSchema(readOnlyServiceFooMethodDescriptor),
connect.WithClientOptions(opts...),
),
}
}
// readOnlyServiceClient implements ReadOnlyServiceClient.
type readOnlyServiceClient struct {
foo *connect.Client[v1.FooRequest, v1.FooResponse]
}
// Foo calls clconnect.v1.ReadOnlyService.Foo.
func (c *readOnlyServiceClient) Foo(ctx context.Context, req *connect.Request[v1.FooRequest]) (*connect.Response[v1.FooResponse], error) {
return c.foo.CallUnary(ctx, req)
}
// ReadOnlyServiceHandler is an implementation of the clconnect.v1.ReadOnlyService service.
type ReadOnlyServiceHandler interface {
// Foo method for testing
Foo(context.Context, *connect.Request[v1.FooRequest]) (*connect.Response[v1.FooResponse], error)
}
// NewReadOnlyServiceHandler builds an HTTP handler from the service implementation. It returns the
// path on which to mount the handler and the handler itself.
//
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
// and JSON codecs. They also support gzip compression.
func NewReadOnlyServiceHandler(svc ReadOnlyServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
readOnlyServiceFooHandler := connect.NewUnaryHandler(
ReadOnlyServiceFooProcedure,
svc.Foo,
connect.WithSchema(readOnlyServiceFooMethodDescriptor),
connect.WithHandlerOptions(opts...),
)
return "/clconnect.v1.ReadOnlyService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case ReadOnlyServiceFooProcedure:
readOnlyServiceFooHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})
}
// UnimplementedReadOnlyServiceHandler returns CodeUnimplemented from all methods.
type UnimplementedReadOnlyServiceHandler struct{}
func (UnimplementedReadOnlyServiceHandler) Foo(context.Context, *connect.Request[v1.FooRequest]) (*connect.Response[v1.FooResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("clconnect.v1.ReadOnlyService.Foo is not implemented"))
}
// ReadWriteServiceClient is a client for the clconnect.v1.ReadWriteService service.
type ReadWriteServiceClient interface {
// Check health endpoint for testing middleware
CheckHealth(context.Context, *connect.Request[v1.CheckHealthRequest]) (*connect.Response[v1.CheckHealthResponse], error)
}
// NewReadWriteServiceClient constructs a client for the clconnect.v1.ReadWriteService service. By
// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses,
// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the
// connect.WithGRPC() or connect.WithGRPCWeb() options.
//
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
// http://api.acme.com or https://acme.com/grpc).
func NewReadWriteServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ReadWriteServiceClient {
baseURL = strings.TrimRight(baseURL, "/")
return &readWriteServiceClient{
checkHealth: connect.NewClient[v1.CheckHealthRequest, v1.CheckHealthResponse](
httpClient,
baseURL+ReadWriteServiceCheckHealthProcedure,
connect.WithSchema(readWriteServiceCheckHealthMethodDescriptor),
connect.WithClientOptions(opts...),
),
}
}
// readWriteServiceClient implements ReadWriteServiceClient.
type readWriteServiceClient struct {
checkHealth *connect.Client[v1.CheckHealthRequest, v1.CheckHealthResponse]
}
// CheckHealth calls clconnect.v1.ReadWriteService.CheckHealth.
func (c *readWriteServiceClient) CheckHealth(ctx context.Context, req *connect.Request[v1.CheckHealthRequest]) (*connect.Response[v1.CheckHealthResponse], error) {
return c.checkHealth.CallUnary(ctx, req)
}
// ReadWriteServiceHandler is an implementation of the clconnect.v1.ReadWriteService service.
type ReadWriteServiceHandler interface {
// Check health endpoint for testing middleware
CheckHealth(context.Context, *connect.Request[v1.CheckHealthRequest]) (*connect.Response[v1.CheckHealthResponse], error)
}
// NewReadWriteServiceHandler builds an HTTP handler from the service implementation. It returns the
// path on which to mount the handler and the handler itself.
//
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
// and JSON codecs. They also support gzip compression.
func NewReadWriteServiceHandler(svc ReadWriteServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
readWriteServiceCheckHealthHandler := connect.NewUnaryHandler(
ReadWriteServiceCheckHealthProcedure,
svc.CheckHealth,
connect.WithSchema(readWriteServiceCheckHealthMethodDescriptor),
connect.WithHandlerOptions(opts...),
)
return "/clconnect.v1.ReadWriteService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case ReadWriteServiceCheckHealthProcedure:
readWriteServiceCheckHealthHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})
}
// UnimplementedReadWriteServiceHandler returns CodeUnimplemented from all methods.
type UnimplementedReadWriteServiceHandler struct{}
func (UnimplementedReadWriteServiceHandler) CheckHealth(context.Context, *connect.Request[v1.CheckHealthRequest]) (*connect.Response[v1.CheckHealthResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("clconnect.v1.ReadWriteService.CheckHealth is not implemented"))
}