mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-15 12:34:44 +00:00
Generate typesafe typescript and go clients, examples (#194)
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
type Helloworld struct{}
|
||||
|
||||
// Call is a single request handler called via client.Call or the generated client code
|
||||
func (e *Helloworld) Call(ctx context.Context, req *helloworld.Request, rsp *helloworld.Response) error {
|
||||
func (e *Helloworld) Call(ctx context.Context, req *helloworld.CallRequest, rsp *helloworld.CallResponse) error {
|
||||
logger.Info("Received Helloworld.Call request")
|
||||
rsp.Message = "Hello " + req.Name
|
||||
return nil
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.15.6
|
||||
// protoc v3.6.1
|
||||
// source: proto/helloworld.proto
|
||||
|
||||
package helloworld
|
||||
@@ -21,7 +21,7 @@ const (
|
||||
)
|
||||
|
||||
// Call returns a personalised "Hello $name" response
|
||||
type Request struct {
|
||||
type CallRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
@@ -29,8 +29,8 @@ type Request struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Request) Reset() {
|
||||
*x = Request{}
|
||||
func (x *CallRequest) Reset() {
|
||||
*x = CallRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_helloworld_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -38,13 +38,13 @@ func (x *Request) Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Request) String() string {
|
||||
func (x *CallRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Request) ProtoMessage() {}
|
||||
func (*CallRequest) ProtoMessage() {}
|
||||
|
||||
func (x *Request) ProtoReflect() protoreflect.Message {
|
||||
func (x *CallRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_helloworld_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -56,19 +56,19 @@ func (x *Request) ProtoReflect() protoreflect.Message {
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
|
||||
func (*Request) Descriptor() ([]byte, []int) {
|
||||
// Deprecated: Use CallRequest.ProtoReflect.Descriptor instead.
|
||||
func (*CallRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_helloworld_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Request) GetName() string {
|
||||
func (x *CallRequest) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
type CallResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
@@ -76,8 +76,8 @@ type Response struct {
|
||||
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Response) Reset() {
|
||||
*x = Response{}
|
||||
func (x *CallResponse) Reset() {
|
||||
*x = CallResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_helloworld_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -85,13 +85,13 @@ func (x *Response) Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Response) String() string {
|
||||
func (x *CallResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Response) ProtoMessage() {}
|
||||
func (*CallResponse) ProtoMessage() {}
|
||||
|
||||
func (x *Response) ProtoReflect() protoreflect.Message {
|
||||
func (x *CallResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_helloworld_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -103,12 +103,12 @@ func (x *Response) ProtoReflect() protoreflect.Message {
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
|
||||
func (*Response) Descriptor() ([]byte, []int) {
|
||||
// Deprecated: Use CallResponse.ProtoReflect.Descriptor instead.
|
||||
func (*CallResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_helloworld_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Response) GetMessage() string {
|
||||
func (x *CallResponse) GetMessage() string {
|
||||
if x != nil {
|
||||
return x.Message
|
||||
}
|
||||
@@ -223,21 +223,22 @@ var File_proto_helloworld_proto protoreflect.FileDescriptor
|
||||
var file_proto_helloworld_proto_rawDesc = []byte{
|
||||
0x0a, 0x16, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72,
|
||||
0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77,
|
||||
0x6f, 0x72, 0x6c, 0x64, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||
0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e,
|
||||
0x61, 0x6d, 0x65, 0x22, 0x24, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, 0x0a, 0x0d, 0x53, 0x74, 0x72,
|
||||
0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61,
|
||||
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a,
|
||||
0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03,
|
||||
0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x22, 0x2a, 0x0a, 0x0e, 0x53, 0x74,
|
||||
0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07,
|
||||
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d,
|
||||
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x86, 0x01, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f,
|
||||
0x77, 0x6f, 0x72, 0x6c, 0x64, 0x12, 0x33, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x13, 0x2e,
|
||||
0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x1a, 0x14, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e,
|
||||
0x6f, 0x72, 0x6c, 0x64, 0x22, 0x21, 0x0a, 0x0b, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x28, 0x0a, 0x0c, 0x43, 0x61, 0x6c, 0x6c, 0x52,
|
||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||
0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x22, 0x3f, 0x0a, 0x0d, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x73, 0x22, 0x2a, 0x0a, 0x0e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x8e,
|
||||
0x01, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x12, 0x3b, 0x0a,
|
||||
0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x17, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72,
|
||||
0x6c, 0x64, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18,
|
||||
0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x43, 0x61, 0x6c, 0x6c,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x06, 0x53, 0x74,
|
||||
0x72, 0x65, 0x61, 0x6d, 0x12, 0x19, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c,
|
||||
0x64, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
||||
@@ -261,15 +262,15 @@ func file_proto_helloworld_proto_rawDescGZIP() []byte {
|
||||
|
||||
var file_proto_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_proto_helloworld_proto_goTypes = []interface{}{
|
||||
(*Request)(nil), // 0: helloworld.Request
|
||||
(*Response)(nil), // 1: helloworld.Response
|
||||
(*CallRequest)(nil), // 0: helloworld.CallRequest
|
||||
(*CallResponse)(nil), // 1: helloworld.CallResponse
|
||||
(*StreamRequest)(nil), // 2: helloworld.StreamRequest
|
||||
(*StreamResponse)(nil), // 3: helloworld.StreamResponse
|
||||
}
|
||||
var file_proto_helloworld_proto_depIdxs = []int32{
|
||||
0, // 0: helloworld.Helloworld.Call:input_type -> helloworld.Request
|
||||
0, // 0: helloworld.Helloworld.Call:input_type -> helloworld.CallRequest
|
||||
2, // 1: helloworld.Helloworld.Stream:input_type -> helloworld.StreamRequest
|
||||
1, // 2: helloworld.Helloworld.Call:output_type -> helloworld.Response
|
||||
1, // 2: helloworld.Helloworld.Call:output_type -> helloworld.CallResponse
|
||||
3, // 3: helloworld.Helloworld.Stream:output_type -> helloworld.StreamResponse
|
||||
2, // [2:4] is the sub-list for method output_type
|
||||
0, // [0:2] is the sub-list for method input_type
|
||||
@@ -285,7 +286,7 @@ func file_proto_helloworld_proto_init() {
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_proto_helloworld_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Request); i {
|
||||
switch v := v.(*CallRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -297,7 +298,7 @@ func file_proto_helloworld_proto_init() {
|
||||
}
|
||||
}
|
||||
file_proto_helloworld_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Response); i {
|
||||
switch v := v.(*CallResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
|
||||
@@ -42,7 +42,7 @@ func NewHelloworldEndpoints() []*api.Endpoint {
|
||||
// Client API for Helloworld service
|
||||
|
||||
type HelloworldService interface {
|
||||
Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error)
|
||||
Call(ctx context.Context, in *CallRequest, opts ...client.CallOption) (*CallResponse, error)
|
||||
Stream(ctx context.Context, in *StreamRequest, opts ...client.CallOption) (Helloworld_StreamService, error)
|
||||
}
|
||||
|
||||
@@ -58,9 +58,9 @@ func NewHelloworldService(name string, c client.Client) HelloworldService {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *helloworldService) Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) {
|
||||
func (c *helloworldService) Call(ctx context.Context, in *CallRequest, opts ...client.CallOption) (*CallResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Helloworld.Call", in)
|
||||
out := new(Response)
|
||||
out := new(CallResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -120,13 +120,13 @@ func (x *helloworldServiceStream) Recv() (*StreamResponse, error) {
|
||||
// Server API for Helloworld service
|
||||
|
||||
type HelloworldHandler interface {
|
||||
Call(context.Context, *Request, *Response) error
|
||||
Call(context.Context, *CallRequest, *CallResponse) error
|
||||
Stream(context.Context, *StreamRequest, Helloworld_StreamStream) error
|
||||
}
|
||||
|
||||
func RegisterHelloworldHandler(s server.Server, hdlr HelloworldHandler, opts ...server.HandlerOption) error {
|
||||
type helloworld interface {
|
||||
Call(ctx context.Context, in *Request, out *Response) error
|
||||
Call(ctx context.Context, in *CallRequest, out *CallResponse) error
|
||||
Stream(ctx context.Context, stream server.Stream) error
|
||||
}
|
||||
type Helloworld struct {
|
||||
@@ -140,7 +140,7 @@ type helloworldHandler struct {
|
||||
HelloworldHandler
|
||||
}
|
||||
|
||||
func (h *helloworldHandler) Call(ctx context.Context, in *Request, out *Response) error {
|
||||
func (h *helloworldHandler) Call(ctx context.Context, in *CallRequest, out *CallResponse) error {
|
||||
return h.HelloworldHandler.Call(ctx, in, out)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,16 @@ package helloworld;
|
||||
option go_package = "./proto;helloworld";
|
||||
|
||||
service Helloworld {
|
||||
rpc Call(Request) returns (Response) {};
|
||||
rpc Call(CallRequest) returns (CallResponse) {};
|
||||
rpc Stream(StreamRequest) returns (stream StreamResponse) {};
|
||||
}
|
||||
|
||||
// Call returns a personalised "Hello $name" response
|
||||
message Request {
|
||||
message CallRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message Response {
|
||||
message CallResponse {
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user