api/router: avoid unneeded loops and fix path match (#1594)

* api/router: avoid unneeded loops and fix path match

* if match found in google api path syntax, not try pcre loop
* if path is not ending via $ sign, append it to pcre to avoid matching other strings like
  /api/account/register can be matched to /api/account
* api: add tests and validations

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-04-29 15:23:10 +03:00 committed by GitHub
parent c7440274dd
commit d44adafca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 645 additions and 107 deletions

View File

@ -128,9 +128,18 @@ func Validate(e *Endpoint) error {
}
for _, p := range e.Path {
_, err := regexp.CompilePOSIX(p)
if err != nil {
return err
ps := p[0]
pe := p[len(p)-1]
if ps == '^' && pe == '$' {
_, err := regexp.CompilePOSIX(p)
if err != nil {
return err
}
} else if ps == '^' && pe != '$' {
return errors.New("invalid path")
} else if ps != '^' && pe == '$' {
return errors.New("invalid path")
}
}

View File

@ -111,3 +111,42 @@ func TestEncoding(t *testing.T) {
}
}
}
func TestValidate(t *testing.T) {
epPcre := &Endpoint{
Name: "Foo.Bar",
Description: "A test endpoint",
Handler: "meta",
Host: []string{"foo.com"},
Method: []string{"GET"},
Path: []string{"^/test/?$"},
}
if err := Validate(epPcre); err != nil {
t.Fatal(err)
}
epGpath := &Endpoint{
Name: "Foo.Bar",
Description: "A test endpoint",
Handler: "meta",
Host: []string{"foo.com"},
Method: []string{"GET"},
Path: []string{"/test/{id}"},
}
if err := Validate(epGpath); err != nil {
t.Fatal(err)
}
epPcreInvalid := &Endpoint{
Name: "Foo.Bar",
Description: "A test endpoint",
Handler: "meta",
Host: []string{"foo.com"},
Method: []string{"GET"},
Path: []string{"/test/?$"},
}
if err := Validate(epPcreInvalid); err == nil {
t.Fatalf("invalid pcre %v", epPcreInvalid.Path[0])
}
}

View File

@ -187,10 +187,13 @@ func (r *registryRouter) store(services []*registry.Service) {
for _, p := range ep.Endpoint.Path {
var pcreok bool
pcrereg, err := regexp.CompilePOSIX(p)
if err == nil {
cep.pcreregs = append(cep.pcreregs, pcrereg)
pcreok = true
if p[0] == '^' && p[len(p)-1] != '$' {
pcrereg, err := regexp.CompilePOSIX(p)
if err == nil {
cep.pcreregs = append(cep.pcreregs, pcrereg)
pcreok = true
}
}
rule, err := util.Parse(p)
@ -359,6 +362,9 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
}
continue
}
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("api gpath match %s = %v", path, pathreg)
}
pMatch = true
ctx := req.Context()
md, ok := metadata.FromContext(ctx)
@ -373,16 +379,21 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
break
}
// 4. try path via pcre path matching
for _, pathreg := range cep.pcreregs {
if !pathreg.MatchString(req.URL.Path) {
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("api pcre path not match %s != %v", path, pathreg)
if !pMatch {
// 4. try path via pcre path matching
for _, pathreg := range cep.pcreregs {
if !pathreg.MatchString(req.URL.Path) {
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("api pcre path not match %s != %v", path, pathreg)
}
continue
}
continue
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("api pcre path match %s != %v", path, pathreg)
}
pMatch = true
break
}
pMatch = true
break
}
if !pMatch {

View File

@ -34,6 +34,18 @@ func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response
return nil
}
// TestHello implements helloworld.GreeterServer
func (s *testServer) CallPcre(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
rsp.Msg = "Hello " + req.Uuid
return nil
}
// TestHello implements helloworld.GreeterServer
func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
rsp.Msg = "Hello " + req.Uuid
return nil
}
func initial(t *testing.T) (server.Server, client.Client) {
r := rmemory.NewRegistry()
@ -81,7 +93,7 @@ func check(t *testing.T, addr string, path string, expected string) {
}
}
func TestRouterRegistry(t *testing.T) {
func TestRouterRegistryPcre(t *testing.T) {
s, c := initial(t)
defer s.Stop()
@ -152,7 +164,7 @@ func TestRouterStaticPcre(t *testing.T) {
check(t, hsrv.Addr, "http://%s/api/v0/test/call", `{"msg":"Hello "}`)
}
func TestRouterStaticG(t *testing.T) {
func TestRouterStaticGpath(t *testing.T) {
s, c := initial(t)
defer s.Stop()
@ -192,3 +204,42 @@ func TestRouterStaticG(t *testing.T) {
time.Sleep(1 * time.Second)
check(t, hsrv.Addr, "http://%s/api/v0/test/call/TEST", `{"msg":"Hello TEST"}`)
}
func TestRouterStaticPcreInvalid(t *testing.T) {
var ep *api.Endpoint
var err error
s, c := initial(t)
defer s.Stop()
router := rstatic.NewRouter(
router.WithHandler(rpc.Handler),
router.WithRegistry(s.Options().Registry),
)
ep = &api.Endpoint{
Name: "foo.Test.Call",
Method: []string{"POST"},
Path: []string{"^/api/v0/test/call/?"},
Handler: "rpc",
}
err = router.Register(ep)
if err == nil {
t.Fatalf("invalid endpoint %v", ep)
}
ep = &api.Endpoint{
Name: "foo.Test.Call",
Method: []string{"POST"},
Path: []string{"/api/v0/test/call/?$"},
Handler: "rpc",
}
err = router.Register(ep)
if err == nil {
t.Fatalf("invalid endpoint %v", ep)
}
_ = c
}

View File

@ -110,10 +110,14 @@ func (r *staticRouter) Register(ep *api.Endpoint) error {
for _, p := range ep.Path {
var pcreok bool
pcrereg, err := regexp.CompilePOSIX(p)
if err == nil {
pcreregs = append(pcreregs, pcrereg)
pcreok = true
// pcre only when we have start and end markers
if p[0] == '^' && p[len(p)-1] == '$' {
pcrereg, err := regexp.CompilePOSIX(p)
if err == nil {
pcreregs = append(pcreregs, pcrereg)
pcreok = true
}
}
rule, err := util.Parse(p)
@ -122,6 +126,7 @@ func (r *staticRouter) Register(ep *api.Endpoint) error {
} else if err != nil && pcreok {
continue
}
tpl := rule.Compile()
pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "")
if err != nil {
@ -280,6 +285,9 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
}
continue
}
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("api gpath match %s = %v", path, pathreg)
}
pMatch = true
ctx := req.Context()
md, ok := metadata.FromContext(ctx)
@ -294,16 +302,18 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
break
}
// 4. try path via pcre path matching
for _, pathreg := range ep.pcreregs {
if !pathreg.MatchString(req.URL.Path) {
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("api pcre path not match %s != %v", req.URL.Path, pathreg)
if !pMatch {
// 4. try path via pcre path matching
for _, pathreg := range ep.pcreregs {
if !pathreg.MatchString(req.URL.Path) {
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("api pcre path not match %s != %v", req.URL.Path, pathreg)
}
continue
}
continue
pMatch = true
break
}
pMatch = true
break
}
if !pMatch {

View File

@ -1,11 +1,15 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto
// source: runtime/service/proto/runtime.proto
package go_micro_runtime
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"
)
@ -38,7 +42,7 @@ 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_976fccef828ab1f0, []int{0}
return fileDescriptor_2434d8152598889b, []int{0}
}
func (m *Service) XXX_Unmarshal(b []byte) error {
@ -101,7 +105,7 @@ func (m *Event) Reset() { *m = Event{} }
func (m *Event) String() string { return proto.CompactTextString(m) }
func (*Event) ProtoMessage() {}
func (*Event) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{1}
return fileDescriptor_2434d8152598889b, []int{1}
}
func (m *Event) XXX_Unmarshal(b []byte) error {
@ -172,7 +176,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} }
func (m *CreateOptions) String() string { return proto.CompactTextString(m) }
func (*CreateOptions) ProtoMessage() {}
func (*CreateOptions) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{2}
return fileDescriptor_2434d8152598889b, []int{2}
}
func (m *CreateOptions) XXX_Unmarshal(b []byte) error {
@ -247,7 +251,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} }
func (m *CreateRequest) String() string { return proto.CompactTextString(m) }
func (*CreateRequest) ProtoMessage() {}
func (*CreateRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{3}
return fileDescriptor_2434d8152598889b, []int{3}
}
func (m *CreateRequest) XXX_Unmarshal(b []byte) error {
@ -292,7 +296,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} }
func (m *CreateResponse) String() string { return proto.CompactTextString(m) }
func (*CreateResponse) ProtoMessage() {}
func (*CreateResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{4}
return fileDescriptor_2434d8152598889b, []int{4}
}
func (m *CreateResponse) XXX_Unmarshal(b []byte) error {
@ -329,7 +333,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} }
func (m *ReadOptions) String() string { return proto.CompactTextString(m) }
func (*ReadOptions) ProtoMessage() {}
func (*ReadOptions) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{5}
return fileDescriptor_2434d8152598889b, []int{5}
}
func (m *ReadOptions) XXX_Unmarshal(b []byte) error {
@ -382,7 +386,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} }
func (m *ReadRequest) String() string { return proto.CompactTextString(m) }
func (*ReadRequest) ProtoMessage() {}
func (*ReadRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{6}
return fileDescriptor_2434d8152598889b, []int{6}
}
func (m *ReadRequest) XXX_Unmarshal(b []byte) error {
@ -421,7 +425,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} }
func (m *ReadResponse) String() string { return proto.CompactTextString(m) }
func (*ReadResponse) ProtoMessage() {}
func (*ReadResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{7}
return fileDescriptor_2434d8152598889b, []int{7}
}
func (m *ReadResponse) XXX_Unmarshal(b []byte) error {
@ -460,7 +464,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} }
func (m *DeleteRequest) String() string { return proto.CompactTextString(m) }
func (*DeleteRequest) ProtoMessage() {}
func (*DeleteRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{8}
return fileDescriptor_2434d8152598889b, []int{8}
}
func (m *DeleteRequest) XXX_Unmarshal(b []byte) error {
@ -498,7 +502,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} }
func (m *DeleteResponse) String() string { return proto.CompactTextString(m) }
func (*DeleteResponse) ProtoMessage() {}
func (*DeleteResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{9}
return fileDescriptor_2434d8152598889b, []int{9}
}
func (m *DeleteResponse) XXX_Unmarshal(b []byte) error {
@ -530,7 +534,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} }
func (m *UpdateRequest) String() string { return proto.CompactTextString(m) }
func (*UpdateRequest) ProtoMessage() {}
func (*UpdateRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{10}
return fileDescriptor_2434d8152598889b, []int{10}
}
func (m *UpdateRequest) XXX_Unmarshal(b []byte) error {
@ -568,7 +572,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} }
func (m *UpdateResponse) String() string { return proto.CompactTextString(m) }
func (*UpdateResponse) ProtoMessage() {}
func (*UpdateResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{11}
return fileDescriptor_2434d8152598889b, []int{11}
}
func (m *UpdateResponse) XXX_Unmarshal(b []byte) error {
@ -599,7 +603,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} }
func (m *ListRequest) String() string { return proto.CompactTextString(m) }
func (*ListRequest) ProtoMessage() {}
func (*ListRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{12}
return fileDescriptor_2434d8152598889b, []int{12}
}
func (m *ListRequest) XXX_Unmarshal(b []byte) error {
@ -631,7 +635,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} }
func (m *ListResponse) String() string { return proto.CompactTextString(m) }
func (*ListResponse) ProtoMessage() {}
func (*ListResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{13}
return fileDescriptor_2434d8152598889b, []int{13}
}
func (m *ListResponse) XXX_Unmarshal(b []byte) error {
@ -679,7 +683,7 @@ func (m *LogsRequest) Reset() { *m = LogsRequest{} }
func (m *LogsRequest) String() string { return proto.CompactTextString(m) }
func (*LogsRequest) ProtoMessage() {}
func (*LogsRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{14}
return fileDescriptor_2434d8152598889b, []int{14}
}
func (m *LogsRequest) XXX_Unmarshal(b []byte) error {
@ -744,7 +748,7 @@ func (m *LogRecord) Reset() { *m = LogRecord{} }
func (m *LogRecord) String() string { return proto.CompactTextString(m) }
func (*LogRecord) ProtoMessage() {}
func (*LogRecord) Descriptor() ([]byte, []int) {
return fileDescriptor_976fccef828ab1f0, []int{15}
return fileDescriptor_2434d8152598889b, []int{15}
}
func (m *LogRecord) XXX_Unmarshal(b []byte) error {
@ -808,51 +812,302 @@ func init() {
}
func init() {
proto.RegisterFile("github.com/micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_976fccef828ab1f0)
proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b)
}
var fileDescriptor_976fccef828ab1f0 = []byte{
// 662 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0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 0xc2, 0x28, 0x34, 0x24, 0xc8, 0x15, 0x0c, 0xcd, 0x02, 0x91, 0xce, 0xa5, 0xb3, 0xf6, 0x1e,
0x4f, 0xbb, 0x0b, 0x6c, 0x97, 0xf7, 0xc8, 0x17, 0xe8, 0xab, 0xf1, 0x26, 0x1d, 0xeb, 0x50, 0x42,
0x3d, 0xef, 0xfa, 0xb9, 0x02, 0xba, 0x82, 0xa1, 0x19, 0xcd, 0x36, 0x5e, 0x8d, 0xd1, 0x6f, 0xe3,
0xb5, 0x31, 0xd5, 0x1a, 0xce, 0x4c, 0x64, 0x1b, 0x5c, 0x63, 0xe2, 0xdb, 0xe0, 0x36, 0x86, 0x79,
0x8f, 0x5c, 0x40, 0x5f, 0x0d, 0x5e, 0x9b, 0xcc, 0xda, 0x40, 0x1e, 0x3f, 0x79, 0xa0, 0xe9, 0xfe,
0xde, 0x1b, 0xe7, 0x66, 0xa8, 0xff, 0x2f, 0x4f, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x40, 0x42,
0xb3, 0x4e, 0x70, 0x07, 0x00, 0x00,
var fileDescriptor_2434d8152598889b = []byte{
// 645 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xc9, 0x6e, 0xdb, 0x30,
0x10, 0x8d, 0x2c, 0x2f, 0xc9, 0xa8, 0x2e, 0x02, 0x22, 0x28, 0xd4, 0x74, 0x33, 0xd4, 0x43, 0xd3,
0x8b, 0x52, 0x38, 0x28, 0xba, 0x1d, 0x63, 0xa7, 0x17, 0x1b, 0x05, 0x54, 0xe4, 0x03, 0x58, 0x79,
0x60, 0x08, 0x89, 0x44, 0x55, 0xa4, 0x0c, 0xf8, 0xd4, 0x63, 0xcf, 0xfd, 0xaa, 0x9e, 0xfb, 0x47,
0x05, 0x17, 0x6d, 0xb6, 0x94, 0x8b, 0x6f, 0x9c, 0x11, 0xf9, 0xf8, 0xde, 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0xcb, 0xab, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x20, 0x0e, 0x37,
0xf1, 0x56, 0x07, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// 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.SupportPackageIsVersion4
// RuntimeClient is the client API for Runtime service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type RuntimeClient interface {
Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error)
Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error)
Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error)
Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error)
Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error)
}
type runtimeClient struct {
cc *grpc.ClientConn
}
func NewRuntimeClient(cc *grpc.ClientConn) RuntimeClient {
return &runtimeClient{cc}
}
func (c *runtimeClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) {
out := new(CreateResponse)
err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Create", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *runtimeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) {
out := new(ReadResponse)
err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Read", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *runtimeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) {
out := new(DeleteResponse)
err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Delete", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *runtimeClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) {
out := new(UpdateResponse)
err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Update", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *runtimeClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error) {
stream, err := c.cc.NewStream(ctx, &_Runtime_serviceDesc.Streams[0], "/go.micro.runtime.Runtime/Logs", opts...)
if err != nil {
return nil, err
}
x := &runtimeLogsClient{stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type Runtime_LogsClient interface {
Recv() (*LogRecord, error)
grpc.ClientStream
}
type runtimeLogsClient struct {
grpc.ClientStream
}
func (x *runtimeLogsClient) Recv() (*LogRecord, error) {
m := new(LogRecord)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// RuntimeServer is the server API for Runtime service.
type RuntimeServer interface {
Create(context.Context, *CreateRequest) (*CreateResponse, error)
Read(context.Context, *ReadRequest) (*ReadResponse, error)
Delete(context.Context, *DeleteRequest) (*DeleteResponse, error)
Update(context.Context, *UpdateRequest) (*UpdateResponse, error)
Logs(*LogsRequest, Runtime_LogsServer) error
}
// UnimplementedRuntimeServer can be embedded to have forward compatible implementations.
type UnimplementedRuntimeServer struct {
}
func (*UnimplementedRuntimeServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Create not implemented")
}
func (*UnimplementedRuntimeServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Read not implemented")
}
func (*UnimplementedRuntimeServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented")
}
func (*UnimplementedRuntimeServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Update not implemented")
}
func (*UnimplementedRuntimeServer) Logs(req *LogsRequest, srv Runtime_LogsServer) error {
return status.Errorf(codes.Unimplemented, "method Logs not implemented")
}
func RegisterRuntimeServer(s *grpc.Server, srv RuntimeServer) {
s.RegisterService(&_Runtime_serviceDesc, srv)
}
func _Runtime_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreateRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RuntimeServer).Create(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/go.micro.runtime.Runtime/Create",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RuntimeServer).Create(ctx, req.(*CreateRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Runtime_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReadRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RuntimeServer).Read(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/go.micro.runtime.Runtime/Read",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RuntimeServer).Read(ctx, req.(*ReadRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Runtime_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RuntimeServer).Delete(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/go.micro.runtime.Runtime/Delete",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RuntimeServer).Delete(ctx, req.(*DeleteRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Runtime_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RuntimeServer).Update(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/go.micro.runtime.Runtime/Update",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RuntimeServer).Update(ctx, req.(*UpdateRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Runtime_Logs_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(LogsRequest)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(RuntimeServer).Logs(m, &runtimeLogsServer{stream})
}
type Runtime_LogsServer interface {
Send(*LogRecord) error
grpc.ServerStream
}
type runtimeLogsServer struct {
grpc.ServerStream
}
func (x *runtimeLogsServer) Send(m *LogRecord) error {
return x.ServerStream.SendMsg(m)
}
var _Runtime_serviceDesc = grpc.ServiceDesc{
ServiceName: "go.micro.runtime.Runtime",
HandlerType: (*RuntimeServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Create",
Handler: _Runtime_Create_Handler,
},
{
MethodName: "Read",
Handler: _Runtime_Read_Handler,
},
{
MethodName: "Delete",
Handler: _Runtime_Delete_Handler,
},
{
MethodName: "Update",
Handler: _Runtime_Update_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "Logs",
Handler: _Runtime_Logs_Handler,
ServerStreams: true,
},
},
Metadata: "runtime/service/proto/runtime.proto",
}

View File

@ -1,5 +1,5 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto
// source: runtime/service/proto/runtime.proto
package go_micro_runtime

View File

@ -33,6 +33,26 @@ func (s *testServer) HandleError(ctx context.Context, msg *pb.Request) error {
return fmt.Errorf("fake")
}
// TestHello implements helloworld.GreeterServer
func (s *testServer) CallPcre(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
if req.Name == "Error" {
return &errors.Error{Id: "1", Code: 99, Detail: "detail"}
}
rsp.Msg = "Hello " + req.Name
return nil
}
// TestHello implements helloworld.GreeterServer
func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
if req.Name == "Error" {
return &errors.Error{Id: "1", Code: 99, Detail: "detail"}
}
rsp.Msg = "Hello " + req.Name
return nil
}
// TestHello implements helloworld.GreeterServer
func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
if req.Name == "Error" {

View File

@ -119,20 +119,24 @@ func init() {
func init() { proto.RegisterFile("server/grpc/proto/test.proto", fileDescriptor_bb9c685b7640cf1e) }
var fileDescriptor_bb9c685b7640cf1e = []byte{
// 198 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x4e, 0x2d, 0x2a,
0x4b, 0x2d, 0xd2, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49,
0x2d, 0x2e, 0xd1, 0x03, 0x33, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b,
0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0xb2, 0x4a,
0x86, 0x5c, 0xec, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x42, 0x5c, 0x2c, 0xa5, 0xa5,
0x99, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x60, 0x36, 0x48, 0x2c, 0x2f, 0x31, 0x37,
0x55, 0x82, 0x09, 0x22, 0x06, 0x62, 0x2b, 0xc9, 0x70, 0x71, 0x04, 0xa5, 0x16, 0x17, 0xe4, 0xe7,
0x15, 0xa7, 0x0a, 0x09, 0x70, 0x31, 0xe7, 0x16, 0xa7, 0x43, 0xb5, 0x80, 0x98, 0x46, 0x1e, 0x5c,
0x2c, 0x21, 0x20, 0xd3, 0x1c, 0xb8, 0x58, 0x9c, 0x13, 0x73, 0x72, 0x84, 0x38, 0xf4, 0xa0, 0xe6,
0x4b, 0x71, 0xea, 0xc1, 0xb4, 0x29, 0x29, 0x37, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x56, 0x49, 0x02,
0xec, 0xaa, 0x32, 0x03, 0xb0, 0x7b, 0xf5, 0x93, 0x13, 0x73, 0x72, 0xf4, 0xab, 0x41, 0xf6, 0xd6,
0x5a, 0x31, 0x6a, 0x25, 0xb1, 0x81, 0x5d, 0x68, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xd0, 0xc1,
0x00, 0x50, 0xdf, 0x00, 0x00, 0x00,
// 261 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0xd0, 0xcf, 0x4a, 0x03, 0x31,
0x10, 0x06, 0x70, 0xb6, 0x2e, 0xba, 0xcd, 0x45, 0xc9, 0x69, 0x59, 0x56, 0x2c, 0xd1, 0x82, 0x54,
0xd8, 0xf1, 0xcf, 0xad, 0x97, 0x0a, 0x82, 0xe0, 0x4d, 0x56, 0xcf, 0x42, 0xdc, 0x0e, 0x4b, 0x20,
0x4d, 0x62, 0x92, 0xdd, 0x8b, 0x78, 0xf1, 0x15, 0x7c, 0x34, 0x5f, 0x41, 0xdf, 0x43, 0x92, 0x6d,
0x4f, 0xb6, 0xb7, 0x8f, 0x09, 0xdf, 0x6f, 0x86, 0x90, 0xd2, 0xa1, 0xed, 0xd1, 0x42, 0x6b, 0x4d,
0x03, 0xc6, 0x6a, 0xaf, 0xc1, 0xa3, 0xf3, 0x55, 0x8c, 0x45, 0xd9, 0x6a, 0xdd, 0x4a, 0x04, 0x6e,
0x04, 0x70, 0xa5, 0xb4, 0xe7, 0x5e, 0x68, 0xe5, 0x86, 0x57, 0x76, 0x45, 0x0e, 0x6a, 0x7c, 0xeb,
0xd0, 0x79, 0x4a, 0x49, 0xda, 0x75, 0x62, 0x99, 0x27, 0x93, 0xe4, 0x7c, 0x5c, 0xc7, 0x1c, 0x66,
0x8a, 0xaf, 0x30, 0x1f, 0x0d, 0xb3, 0x90, 0x59, 0x49, 0xb2, 0x1a, 0x9d, 0xd1, 0xca, 0x21, 0x3d,
0x22, 0x7b, 0x2b, 0xd7, 0xae, 0x2b, 0x21, 0x5e, 0xff, 0x26, 0x24, 0x7d, 0x0e, 0xdc, 0x2d, 0x49,
0xef, 0xb8, 0x94, 0x34, 0xab, 0xd6, 0x0b, 0x8a, 0x71, 0xb5, 0xe9, 0xb1, 0xd3, 0xcf, 0xef, 0x9f,
0xaf, 0xd1, 0x31, 0xcb, 0xe3, 0x59, 0xfd, 0x65, 0x3c, 0x18, 0x1a, 0x2e, 0x25, 0xbc, 0x87, 0xc5,
0x1f, 0xf3, 0x64, 0x46, 0xef, 0x49, 0x16, 0x84, 0xc7, 0xc6, 0xe2, 0x76, 0x65, 0x1a, 0x95, 0x13,
0x56, 0xbc, 0xfc, 0x67, 0x4c, 0x63, 0x11, 0x16, 0x67, 0xc1, 0x79, 0x22, 0x87, 0x1b, 0xe7, 0x41,
0xf5, 0x5c, 0x8a, 0xe5, 0x76, 0xee, 0x22, 0x72, 0x53, 0x36, 0xd9, 0xa1, 0x89, 0xa1, 0x0c, 0x8b,
0x79, 0x32, 0x7b, 0xdd, 0x8f, 0xff, 0x77, 0xf3, 0x17, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x25, 0x7a,
0x7d, 0x7d, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@ -148,6 +152,8 @@ const _ = grpc.SupportPackageIsVersion4
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type TestClient interface {
Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
CallPcre(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
CallPcreInvalid(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
}
type testClient struct {
@ -167,9 +173,29 @@ func (c *testClient) Call(ctx context.Context, in *Request, opts ...grpc.CallOpt
return out, nil
}
func (c *testClient) CallPcre(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
out := new(Response)
err := c.cc.Invoke(ctx, "/Test/CallPcre", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *testClient) CallPcreInvalid(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
out := new(Response)
err := c.cc.Invoke(ctx, "/Test/CallPcreInvalid", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// TestServer is the server API for Test service.
type TestServer interface {
Call(context.Context, *Request) (*Response, error)
CallPcre(context.Context, *Request) (*Response, error)
CallPcreInvalid(context.Context, *Request) (*Response, error)
}
// UnimplementedTestServer can be embedded to have forward compatible implementations.
@ -179,6 +205,12 @@ type UnimplementedTestServer struct {
func (*UnimplementedTestServer) Call(ctx context.Context, req *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Call not implemented")
}
func (*UnimplementedTestServer) CallPcre(ctx context.Context, req *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method CallPcre not implemented")
}
func (*UnimplementedTestServer) CallPcreInvalid(ctx context.Context, req *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method CallPcreInvalid not implemented")
}
func RegisterTestServer(s *grpc.Server, srv TestServer) {
s.RegisterService(&_Test_serviceDesc, srv)
@ -202,6 +234,42 @@ func _Test_Call_Handler(srv interface{}, ctx context.Context, dec func(interface
return interceptor(ctx, in, info, handler)
}
func _Test_CallPcre_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TestServer).CallPcre(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/Test/CallPcre",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TestServer).CallPcre(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _Test_CallPcreInvalid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TestServer).CallPcreInvalid(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/Test/CallPcreInvalid",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TestServer).CallPcreInvalid(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
var _Test_serviceDesc = grpc.ServiceDesc{
ServiceName: "Test",
HandlerType: (*TestServer)(nil),
@ -210,6 +278,14 @@ var _Test_serviceDesc = grpc.ServiceDesc{
MethodName: "Call",
Handler: _Test_Call_Handler,
},
{
MethodName: "CallPcre",
Handler: _Test_CallPcre_Handler,
},
{
MethodName: "CallPcreInvalid",
Handler: _Test_CallPcreInvalid_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "server/grpc/proto/test.proto",

View File

@ -45,6 +45,20 @@ func NewTestEndpoints() []*api.Endpoint {
Body: "*",
Handler: "rpc",
},
&api.Endpoint{
Name: "Test.CallPcre",
Path: []string{"^/api/v0/test/call/pcre/?$"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
&api.Endpoint{
Name: "Test.CallPcreInvalid",
Path: []string{"/api/v0/test/call/pcre/invalid/?"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
}
}
@ -52,6 +66,8 @@ func NewTestEndpoints() []*api.Endpoint {
type TestService interface {
Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error)
CallPcre(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error)
CallPcreInvalid(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error)
}
type testService struct {
@ -76,15 +92,39 @@ func (c *testService) Call(ctx context.Context, in *Request, opts ...client.Call
return out, nil
}
func (c *testService) CallPcre(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) {
req := c.c.NewRequest(c.name, "Test.CallPcre", in)
out := new(Response)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *testService) CallPcreInvalid(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) {
req := c.c.NewRequest(c.name, "Test.CallPcreInvalid", in)
out := new(Response)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Test service
type TestHandler interface {
Call(context.Context, *Request, *Response) error
CallPcre(context.Context, *Request, *Response) error
CallPcreInvalid(context.Context, *Request, *Response) error
}
func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.HandlerOption) error {
type test interface {
Call(ctx context.Context, in *Request, out *Response) error
CallPcre(ctx context.Context, in *Request, out *Response) error
CallPcreInvalid(ctx context.Context, in *Request, out *Response) error
}
type Test struct {
test
@ -97,6 +137,20 @@ func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.Handl
Body: "*",
Handler: "rpc",
}))
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "Test.CallPcre",
Path: []string{"^/api/v0/test/call/pcre/?$"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
opts = append(opts, api.WithEndpoint(&api.Endpoint{
Name: "Test.CallPcreInvalid",
Path: []string{"/api/v0/test/call/pcre/invalid/?"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}))
return s.Handle(s.NewHandler(&Test{h}, opts...))
}
@ -107,3 +161,11 @@ type testHandler struct {
func (h *testHandler) Call(ctx context.Context, in *Request, out *Response) error {
return h.TestHandler.Call(ctx, in, out)
}
func (h *testHandler) CallPcre(ctx context.Context, in *Request, out *Response) error {
return h.TestHandler.CallPcre(ctx, in, out)
}
func (h *testHandler) CallPcreInvalid(ctx context.Context, in *Request, out *Response) error {
return h.TestHandler.CallPcreInvalid(ctx, in, out)
}

View File

@ -6,7 +6,12 @@ service Test {
rpc Call(Request) returns (Response) {
option (google.api.http) = { post: "/api/v0/test/call/{uuid}"; body:"*"; };
};
rpc CallPcre(Request) returns (Response) {
option (google.api.http) = { post: "^/api/v0/test/call/pcre/?$"; body:"*"; };
};
rpc CallPcreInvalid(Request) returns (Response) {
option (google.api.http) = { post: "^/api/v0/test/call/pcre/invalid/?"; body:"*"; };
};
}
message Request {