This commit is contained in:
Minghe Huang
2020-06-09 18:13:35 +08:00
parent d235c5c41d
commit 4fb3073f20
3 changed files with 326 additions and 0 deletions

5
api/Makefile Normal file
View File

@@ -0,0 +1,5 @@
update:
protoc --go_out=plugins=grpc:. --go_opt=paths=source_relative proto/fxd.proto
install:
export GO111MODULE=on
go get github.com/golang/protobuf/protoc-gen-go@v1.3

297
api/api.pb.go Normal file
View File

@@ -0,0 +1,297 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: api.proto
package api
import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Filter struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Filter) Reset() { *m = Filter{} }
func (m *Filter) String() string { return proto.CompactTextString(m) }
func (*Filter) ProtoMessage() {}
func (*Filter) Descriptor() ([]byte, []int) {
return fileDescriptor_00212fb1f9d3bf1c, []int{0}
}
func (m *Filter) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Filter.Unmarshal(m, b)
}
func (m *Filter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Filter.Marshal(b, m, deterministic)
}
func (m *Filter) XXX_Merge(src proto.Message) {
xxx_messageInfo_Filter.Merge(m, src)
}
func (m *Filter) XXX_Size() int {
return xxx_messageInfo_Filter.Size(m)
}
func (m *Filter) XXX_DiscardUnknown() {
xxx_messageInfo_Filter.DiscardUnknown(m)
}
var xxx_messageInfo_Filter proto.InternalMessageInfo
func (m *Filter) GetName() string {
if m != nil {
return m.Name
}
return ""
}
type ListServiceRequest struct {
Filter *Filter `protobuf:"bytes,1,opt,name=filter,proto3" json:"filter,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ListServiceRequest) Reset() { *m = ListServiceRequest{} }
func (m *ListServiceRequest) String() string { return proto.CompactTextString(m) }
func (*ListServiceRequest) ProtoMessage() {}
func (*ListServiceRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_00212fb1f9d3bf1c, []int{1}
}
func (m *ListServiceRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ListServiceRequest.Unmarshal(m, b)
}
func (m *ListServiceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ListServiceRequest.Marshal(b, m, deterministic)
}
func (m *ListServiceRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_ListServiceRequest.Merge(m, src)
}
func (m *ListServiceRequest) XXX_Size() int {
return xxx_messageInfo_ListServiceRequest.Size(m)
}
func (m *ListServiceRequest) XXX_DiscardUnknown() {
xxx_messageInfo_ListServiceRequest.DiscardUnknown(m)
}
var xxx_messageInfo_ListServiceRequest proto.InternalMessageInfo
func (m *ListServiceRequest) GetFilter() *Filter {
if m != nil {
return m.Filter
}
return nil
}
type Service struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Endpoint string `protobuf:"bytes,2,opt,name=endpoint,proto3" json:"endpoint,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Service) Reset() { *m = Service{} }
func (m *Service) String() string { return proto.CompactTextString(m) }
func (*Service) ProtoMessage() {}
func (*Service) Descriptor() ([]byte, []int) {
return fileDescriptor_00212fb1f9d3bf1c, []int{2}
}
func (m *Service) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Service.Unmarshal(m, b)
}
func (m *Service) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Service.Marshal(b, m, deterministic)
}
func (m *Service) XXX_Merge(src proto.Message) {
xxx_messageInfo_Service.Merge(m, src)
}
func (m *Service) XXX_Size() int {
return xxx_messageInfo_Service.Size(m)
}
func (m *Service) XXX_DiscardUnknown() {
xxx_messageInfo_Service.DiscardUnknown(m)
}
var xxx_messageInfo_Service proto.InternalMessageInfo
func (m *Service) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *Service) GetEndpoint() string {
if m != nil {
return m.Endpoint
}
return ""
}
type ListServiceResponse struct {
Services []*Service `protobuf:"bytes,1,rep,name=services,proto3" json:"services,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ListServiceResponse) Reset() { *m = ListServiceResponse{} }
func (m *ListServiceResponse) String() string { return proto.CompactTextString(m) }
func (*ListServiceResponse) ProtoMessage() {}
func (*ListServiceResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_00212fb1f9d3bf1c, []int{3}
}
func (m *ListServiceResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ListServiceResponse.Unmarshal(m, b)
}
func (m *ListServiceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ListServiceResponse.Marshal(b, m, deterministic)
}
func (m *ListServiceResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_ListServiceResponse.Merge(m, src)
}
func (m *ListServiceResponse) XXX_Size() int {
return xxx_messageInfo_ListServiceResponse.Size(m)
}
func (m *ListServiceResponse) XXX_DiscardUnknown() {
xxx_messageInfo_ListServiceResponse.DiscardUnknown(m)
}
var xxx_messageInfo_ListServiceResponse proto.InternalMessageInfo
func (m *ListServiceResponse) GetServices() []*Service {
if m != nil {
return m.Services
}
return nil
}
func init() {
proto.RegisterType((*Filter)(nil), "api.Filter")
proto.RegisterType((*ListServiceRequest)(nil), "api.ListServiceRequest")
proto.RegisterType((*Service)(nil), "api.Service")
proto.RegisterType((*ListServiceResponse)(nil), "api.ListServiceResponse")
}
func init() {
proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c)
}
var fileDescriptor_00212fb1f9d3bf1c = []byte{
// 202 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x2c, 0xc8, 0xd4,
0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x92, 0xe1, 0x62, 0x73, 0xcb,
0xcc, 0x29, 0x49, 0x2d, 0x12, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x54, 0x60,
0xd4, 0xe0, 0x0c, 0x02, 0xb3, 0x95, 0x2c, 0xb9, 0x84, 0x7c, 0x32, 0x8b, 0x4b, 0x82, 0x53, 0x8b,
0xca, 0x32, 0x93, 0x53, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x94, 0xb9, 0xd8, 0xd2,
0xc0, 0x7a, 0xc0, 0x6a, 0xb9, 0x8d, 0xb8, 0xf5, 0x40, 0x86, 0x42, 0x8c, 0x09, 0x82, 0x4a, 0x29,
0x59, 0x72, 0xb1, 0x43, 0xb5, 0x61, 0x33, 0x59, 0x48, 0x8a, 0x8b, 0x23, 0x35, 0x2f, 0xa5, 0x20,
0x3f, 0x33, 0xaf, 0x44, 0x82, 0x09, 0x2c, 0x0e, 0xe7, 0x2b, 0xd9, 0x73, 0x09, 0xa3, 0xd8, 0x5a,
0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0xa4, 0xc1, 0xc5, 0x51, 0x0c, 0x11, 0x2a, 0x96, 0x60, 0x54,
0x60, 0xd6, 0xe0, 0x36, 0xe2, 0x01, 0x5b, 0x0c, 0x53, 0x07, 0x97, 0x35, 0xf2, 0xe4, 0x62, 0x76,
0x0c, 0xf0, 0x14, 0x72, 0xe2, 0xe2, 0x46, 0x32, 0x47, 0x48, 0x1c, 0xac, 0x1a, 0xd3, 0x3f, 0x52,
0x12, 0x98, 0x12, 0x10, 0x2b, 0x95, 0x18, 0x92, 0xd8, 0xc0, 0x61, 0x65, 0x0c, 0x08, 0x00, 0x00,
0xff, 0xff, 0xe4, 0xec, 0x6b, 0xd4, 0x38, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// APIClient is the client API for API service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type APIClient interface {
ListService(ctx context.Context, in *ListServiceRequest, opts ...grpc.CallOption) (*ListServiceResponse, error)
}
type aPIClient struct {
cc grpc.ClientConnInterface
}
func NewAPIClient(cc grpc.ClientConnInterface) APIClient {
return &aPIClient{cc}
}
func (c *aPIClient) ListService(ctx context.Context, in *ListServiceRequest, opts ...grpc.CallOption) (*ListServiceResponse, error) {
out := new(ListServiceResponse)
err := c.cc.Invoke(ctx, "/api.API/ListService", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// APIServer is the server API for API service.
type APIServer interface {
ListService(context.Context, *ListServiceRequest) (*ListServiceResponse, error)
}
// UnimplementedAPIServer can be embedded to have forward compatible implementations.
type UnimplementedAPIServer struct {
}
func (*UnimplementedAPIServer) ListService(ctx context.Context, req *ListServiceRequest) (*ListServiceResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListService not implemented")
}
func RegisterAPIServer(s *grpc.Server, srv APIServer) {
s.RegisterService(&_API_serviceDesc, srv)
}
func _API_ListService_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListServiceRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(APIServer).ListService(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/api.API/ListService",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(APIServer).ListService(ctx, req.(*ListServiceRequest))
}
return interceptor(ctx, in, info, handler)
}
var _API_serviceDesc = grpc.ServiceDesc{
ServiceName: "api.API",
HandlerType: (*APIServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ListService",
Handler: _API_ListService_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api.proto",
}

24
api/api.proto Normal file
View File

@@ -0,0 +1,24 @@
syntax = "proto3";
package api;
service API {
rpc ListService (ListServiceRequest) returns (ListServiceResponse) {}
}
message Filter {
string name = 1;
}
message ListServiceRequest {
Filter filter = 1;
}
message Service {
string name = 1;
string endpoint = 2;
}
message ListServiceResponse {
repeated Service services = 1;
}